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/sched.h>
8 #include <asm/uaccess.h>
10 #include "signaling.h"
13 static int check_addr(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(struct sockaddr_atmsvc
*a
, 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(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
)
50 struct atm_dev_addr
*this, *p
;
52 spin_lock_irqsave(&dev
->lock
, flags
);
53 list_for_each_entry_safe(this, p
, &dev
->local
, entry
)
55 spin_unlock_irqrestore(&dev
->lock
, flags
);
59 int atm_add_addr(struct atm_dev
*dev
, struct sockaddr_atmsvc
*addr
)
62 struct atm_dev_addr
*this;
65 error
= check_addr(addr
);
68 spin_lock_irqsave(&dev
->lock
, flags
);
69 list_for_each_entry(this, &dev
->local
, entry
) {
70 if (identical(&this->addr
, addr
)) {
71 spin_unlock_irqrestore(&dev
->lock
, flags
);
75 this = kmalloc(sizeof(struct atm_dev_addr
), GFP_ATOMIC
);
77 spin_unlock_irqrestore(&dev
->lock
, flags
);
81 list_add(&this->entry
, &dev
->local
);
82 spin_unlock_irqrestore(&dev
->lock
, flags
);
87 int atm_del_addr(struct atm_dev
*dev
, struct sockaddr_atmsvc
*addr
)
90 struct atm_dev_addr
*this;
93 error
= check_addr(addr
);
96 spin_lock_irqsave(&dev
->lock
, flags
);
97 list_for_each_entry(this, &dev
->local
, entry
) {
98 if (identical(&this->addr
, addr
)) {
99 list_del(&this->entry
);
100 spin_unlock_irqrestore(&dev
->lock
, flags
);
106 spin_unlock_irqrestore(&dev
->lock
, flags
);
110 int atm_get_addr(struct atm_dev
*dev
, struct sockaddr_atmsvc __user
* buf
,
114 struct atm_dev_addr
*this;
115 int total
= 0, error
;
116 struct sockaddr_atmsvc
*tmp_buf
, *tmp_bufp
;
118 spin_lock_irqsave(&dev
->lock
, flags
);
119 list_for_each_entry(this, &dev
->local
, entry
)
120 total
+= sizeof(struct sockaddr_atmsvc
);
121 tmp_buf
= tmp_bufp
= kmalloc(total
, GFP_ATOMIC
);
123 spin_unlock_irqrestore(&dev
->lock
, flags
);
126 list_for_each_entry(this, &dev
->local
, entry
)
127 memcpy(tmp_bufp
++, &this->addr
, sizeof(struct sockaddr_atmsvc
));
128 spin_unlock_irqrestore(&dev
->lock
, flags
);
129 error
= total
> size
? -E2BIG
: total
;
130 if (copy_to_user(buf
, tmp_buf
, total
< size
? total
: size
))