1 /* net/atm/addr.c - Local ATM address registry */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
6 #include <linux/atmdev.h>
7 #include <linux/uaccess.h>
12 static int check_addr(const struct sockaddr_atmsvc
*addr
)
16 if (addr
->sas_family
!= AF_ATMSVC
)
18 if (!*addr
->sas_addr
.pub
)
19 return *addr
->sas_addr
.prv
? 0 : -EINVAL
;
20 for (i
= 1; i
< ATM_E164_LEN
+ 1; i
++) /* make sure it's \0-terminated */
21 if (!addr
->sas_addr
.pub
[i
])
26 static int identical(const struct sockaddr_atmsvc
*a
, const struct sockaddr_atmsvc
*b
)
29 if (memcmp(a
->sas_addr
.prv
, b
->sas_addr
.prv
, ATM_ESA_LEN
))
31 if (!*a
->sas_addr
.pub
)
32 return !*b
->sas_addr
.pub
;
33 if (!*b
->sas_addr
.pub
)
35 return !strcmp(a
->sas_addr
.pub
, b
->sas_addr
.pub
);
38 static void notify_sigd(const struct atm_dev
*dev
)
40 struct sockaddr_atmpvc pvc
;
42 pvc
.sap_addr
.itf
= dev
->number
;
43 sigd_enq(NULL
, as_itf_notify
, NULL
, &pvc
, NULL
);
46 void atm_reset_addr(struct atm_dev
*dev
, enum atm_addr_type_t atype
)
49 struct atm_dev_addr
*this, *p
;
50 struct list_head
*head
;
52 spin_lock_irqsave(&dev
->lock
, flags
);
53 if (atype
== ATM_ADDR_LECS
)
57 list_for_each_entry_safe(this, p
, head
, entry
) {
58 list_del(&this->entry
);
61 spin_unlock_irqrestore(&dev
->lock
, flags
);
62 if (head
== &dev
->local
)
66 int atm_add_addr(struct atm_dev
*dev
, const struct sockaddr_atmsvc
*addr
,
67 enum atm_addr_type_t atype
)
70 struct atm_dev_addr
*this;
71 struct list_head
*head
;
74 error
= check_addr(addr
);
77 spin_lock_irqsave(&dev
->lock
, flags
);
78 if (atype
== ATM_ADDR_LECS
)
82 list_for_each_entry(this, head
, entry
) {
83 if (identical(&this->addr
, addr
)) {
84 spin_unlock_irqrestore(&dev
->lock
, flags
);
88 this = kmalloc(sizeof(struct atm_dev_addr
), GFP_ATOMIC
);
90 spin_unlock_irqrestore(&dev
->lock
, flags
);
94 list_add(&this->entry
, head
);
95 spin_unlock_irqrestore(&dev
->lock
, flags
);
96 if (head
== &dev
->local
)
101 int atm_del_addr(struct atm_dev
*dev
, const struct sockaddr_atmsvc
*addr
,
102 enum atm_addr_type_t atype
)
105 struct atm_dev_addr
*this;
106 struct list_head
*head
;
109 error
= check_addr(addr
);
112 spin_lock_irqsave(&dev
->lock
, flags
);
113 if (atype
== ATM_ADDR_LECS
)
117 list_for_each_entry(this, head
, entry
) {
118 if (identical(&this->addr
, addr
)) {
119 list_del(&this->entry
);
120 spin_unlock_irqrestore(&dev
->lock
, flags
);
122 if (head
== &dev
->local
)
127 spin_unlock_irqrestore(&dev
->lock
, flags
);
131 int atm_get_addr(struct atm_dev
*dev
, struct sockaddr_atmsvc __user
* buf
,
132 size_t size
, enum atm_addr_type_t atype
)
135 struct atm_dev_addr
*this;
136 struct list_head
*head
;
137 int total
= 0, error
;
138 struct sockaddr_atmsvc
*tmp_buf
, *tmp_bufp
;
140 spin_lock_irqsave(&dev
->lock
, flags
);
141 if (atype
== ATM_ADDR_LECS
)
145 list_for_each_entry(this, head
, entry
)
146 total
+= sizeof(struct sockaddr_atmsvc
);
147 tmp_buf
= tmp_bufp
= kmalloc(total
, GFP_ATOMIC
);
149 spin_unlock_irqrestore(&dev
->lock
, flags
);
152 list_for_each_entry(this, head
, entry
)
153 memcpy(tmp_bufp
++, &this->addr
, sizeof(struct sockaddr_atmsvc
));
154 spin_unlock_irqrestore(&dev
->lock
, flags
);
155 error
= total
> size
? -E2BIG
: total
;
156 if (copy_to_user(buf
, tmp_buf
, total
< size
? total
: size
))