[PATCH] sound/oss/esssolo1: Use the DMA_32BIT_MASK constant
[pohmelfs.git] / net / atm / addr.c
blob1c8867f7f54a920cdc996b14ba1eebdd8b42dfac
1 /* net/atm/addr.c - Local ATM address registry */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
5 #include <linux/atm.h>
6 #include <linux/atmdev.h>
7 #include <linux/sched.h>
8 #include <asm/uaccess.h>
10 #include "signaling.h"
11 #include "addr.h"
13 static int check_addr(struct sockaddr_atmsvc *addr)
15 int i;
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;
27 static int identical(struct sockaddr_atmsvc *a, struct sockaddr_atmsvc *b)
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);
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)
49 unsigned long flags;
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)
54 kfree(this);
55 spin_unlock_irqrestore(&dev->lock, flags);
56 notify_sigd(dev);
59 int atm_add_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr)
61 unsigned long flags;
62 struct atm_dev_addr *this;
63 int error;
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;
75 this = kmalloc(sizeof(struct atm_dev_addr), GFP_ATOMIC);
76 if (!this) {
77 spin_unlock_irqrestore(&dev->lock, flags);
78 return -ENOMEM;
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;
87 int atm_del_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr)
89 unsigned long flags;
90 struct atm_dev_addr *this;
91 int error;
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;
106 spin_unlock_irqrestore(&dev->lock, flags);
107 return -ENOENT;
110 int atm_get_addr(struct atm_dev *dev, struct sockaddr_atmsvc __user * buf,
111 size_t size)
113 unsigned long flags;
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);
122 if (!tmp_buf) {
123 spin_unlock_irqrestore(&dev->lock, flags);
124 return -ENOMEM;
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;