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/slab.h>
8 #include <linux/uaccess.h>
10 #include "signaling.h"
13 static int check_addr(const struct sockaddr_atmsvc
*addr
)
17 if (addr
->sas_family
!= AF_ATMSVC
)
19 if (!*addr
->sas_addr
.pub
)
20 return *addr
->sas_addr
.prv
? 0 : -EINVAL
;
21 for (i
= 1; i
< ATM_E164_LEN
+ 1; i
++) /* make sure it's \0-terminated */
22 if (!addr
->sas_addr
.pub
[i
])
27 static int identical(const struct sockaddr_atmsvc
*a
, const struct sockaddr_atmsvc
*b
)
30 if (memcmp(a
->sas_addr
.prv
, b
->sas_addr
.prv
, ATM_ESA_LEN
))
32 if (!*a
->sas_addr
.pub
)
33 return !*b
->sas_addr
.pub
;
34 if (!*b
->sas_addr
.pub
)
36 return !strcmp(a
->sas_addr
.pub
, b
->sas_addr
.pub
);
39 static void notify_sigd(const struct atm_dev
*dev
)
41 struct sockaddr_atmpvc pvc
;
43 pvc
.sap_addr
.itf
= dev
->number
;
44 sigd_enq(NULL
, as_itf_notify
, NULL
, &pvc
, NULL
);
47 void atm_reset_addr(struct atm_dev
*dev
, enum atm_addr_type_t atype
)
50 struct atm_dev_addr
*this, *p
;
51 struct list_head
*head
;
53 spin_lock_irqsave(&dev
->lock
, flags
);
54 if (atype
== ATM_ADDR_LECS
)
58 list_for_each_entry_safe(this, p
, head
, entry
) {
59 list_del(&this->entry
);
62 spin_unlock_irqrestore(&dev
->lock
, flags
);
63 if (head
== &dev
->local
)
67 int atm_add_addr(struct atm_dev
*dev
, const struct sockaddr_atmsvc
*addr
,
68 enum atm_addr_type_t atype
)
71 struct atm_dev_addr
*this;
72 struct list_head
*head
;
75 error
= check_addr(addr
);
78 spin_lock_irqsave(&dev
->lock
, flags
);
79 if (atype
== ATM_ADDR_LECS
)
83 list_for_each_entry(this, head
, entry
) {
84 if (identical(&this->addr
, addr
)) {
85 spin_unlock_irqrestore(&dev
->lock
, flags
);
89 this = kmalloc(sizeof(struct atm_dev_addr
), GFP_ATOMIC
);
91 spin_unlock_irqrestore(&dev
->lock
, flags
);
95 list_add(&this->entry
, head
);
96 spin_unlock_irqrestore(&dev
->lock
, flags
);
97 if (head
== &dev
->local
)
102 int atm_del_addr(struct atm_dev
*dev
, const struct sockaddr_atmsvc
*addr
,
103 enum atm_addr_type_t atype
)
106 struct atm_dev_addr
*this;
107 struct list_head
*head
;
110 error
= check_addr(addr
);
113 spin_lock_irqsave(&dev
->lock
, flags
);
114 if (atype
== ATM_ADDR_LECS
)
118 list_for_each_entry(this, head
, entry
) {
119 if (identical(&this->addr
, addr
)) {
120 list_del(&this->entry
);
121 spin_unlock_irqrestore(&dev
->lock
, flags
);
123 if (head
== &dev
->local
)
128 spin_unlock_irqrestore(&dev
->lock
, flags
);
132 int atm_get_addr(struct atm_dev
*dev
, struct sockaddr_atmsvc __user
* buf
,
133 size_t size
, enum atm_addr_type_t atype
)
136 struct atm_dev_addr
*this;
137 struct list_head
*head
;
138 int total
= 0, error
;
139 struct sockaddr_atmsvc
*tmp_buf
, *tmp_bufp
;
141 spin_lock_irqsave(&dev
->lock
, flags
);
142 if (atype
== ATM_ADDR_LECS
)
146 list_for_each_entry(this, head
, entry
)
147 total
+= sizeof(struct sockaddr_atmsvc
);
148 tmp_buf
= tmp_bufp
= kmalloc(total
, GFP_ATOMIC
);
150 spin_unlock_irqrestore(&dev
->lock
, flags
);
153 list_for_each_entry(this, head
, entry
)
154 memcpy(tmp_bufp
++, &this->addr
, sizeof(struct sockaddr_atmsvc
));
155 spin_unlock_irqrestore(&dev
->lock
, flags
);
156 error
= total
> size
? -E2BIG
: total
;
157 if (copy_to_user(buf
, tmp_buf
, total
< size
? total
: size
))
This page took 0.033528 seconds and 5 git commands to generate.