aboutsummaryrefslogtreecommitdiffstats
path: root/net/atm/addr.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/atm/addr.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'net/atm/addr.c')
-rw-r--r--net/atm/addr.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/net/atm/addr.c b/net/atm/addr.c
new file mode 100644
index 000000000000..1c8867f7f54a
--- /dev/null
+++ b/net/atm/addr.c
@@ -0,0 +1,134 @@
1/* net/atm/addr.c - Local ATM address registry */
2
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4
5#include <linux/atm.h>
6#include <linux/atmdev.h>
7#include <linux/sched.h>
8#include <asm/uaccess.h>
9
10#include "signaling.h"
11#include "addr.h"
12
13static int check_addr(struct sockaddr_atmsvc *addr)
14{
15 int i;
16
17 if (addr->sas_family != AF_ATMSVC)
18 return -EAFNOSUPPORT;
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])
23 return 0;
24 return -EINVAL;
25}
26
27static int identical(struct sockaddr_atmsvc *a, struct sockaddr_atmsvc *b)
28{
29 if (*a->sas_addr.prv)
30 if (memcmp(a->sas_addr.prv, b->sas_addr.prv, ATM_ESA_LEN))
31 return 0;
32 if (!*a->sas_addr.pub)
33 return !*b->sas_addr.pub;
34 if (!*b->sas_addr.pub)
35 return 0;
36 return !strcmp(a->sas_addr.pub, b->sas_addr.pub);
37}
38
39static void notify_sigd(struct atm_dev *dev)
40{
41 struct sockaddr_atmpvc pvc;
42
43 pvc.sap_addr.itf = dev->number;
44 sigd_enq(NULL, as_itf_notify, NULL, &pvc, NULL);
45}
46
47void atm_reset_addr(struct atm_dev *dev)
48{
49 unsigned long flags;
50 struct atm_dev_addr *this, *p;
51
52 spin_lock_irqsave(&dev->lock, flags);
53 list_for_each_entry_safe(this, p, &dev->local, entry)
54 kfree(this);
55 spin_unlock_irqrestore(&dev->lock, flags);
56 notify_sigd(dev);
57}
58
59int atm_add_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr)
60{
61 unsigned long flags;
62 struct atm_dev_addr *this;
63 int error;
64
65 error = check_addr(addr);
66 if (error)
67 return error;
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);
72 return -EEXIST;
73 }
74 }
75 this = kmalloc(sizeof(struct atm_dev_addr), GFP_ATOMIC);
76 if (!this) {
77 spin_unlock_irqrestore(&dev->lock, flags);
78 return -ENOMEM;
79 }
80 this->addr = *addr;
81 list_add(&this->entry, &dev->local);
82 spin_unlock_irqrestore(&dev->lock, flags);
83 notify_sigd(dev);
84 return 0;
85}
86
87int atm_del_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr)
88{
89 unsigned long flags;
90 struct atm_dev_addr *this;
91 int error;
92
93 error = check_addr(addr);
94 if (error)
95 return error;
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);
101 kfree(this);
102 notify_sigd(dev);
103 return 0;
104 }
105 }
106 spin_unlock_irqrestore(&dev->lock, flags);
107 return -ENOENT;
108}
109
110int atm_get_addr(struct atm_dev *dev, struct sockaddr_atmsvc __user * buf,
111 size_t size)
112{
113 unsigned long flags;
114 struct atm_dev_addr *this;
115 int total = 0, error;
116 struct sockaddr_atmsvc *tmp_buf, *tmp_bufp;
117
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);
122 if (!tmp_buf) {
123 spin_unlock_irqrestore(&dev->lock, flags);
124 return -ENOMEM;
125 }
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))
131 error = -EFAULT;
132 kfree(tmp_buf);
133 return error;
134}