[ATM]: add support for LECS addresses learned from network
From: Eric Kinzie <ekinzie@cmf.nrl.navy.mil> Signed-off-by: Chas Williams <chas@cmf.nrl.navy.mil> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
20c9c825b1
commit
0f21ba7cc3
4 changed files with 70 additions and 23 deletions
|
@ -76,6 +76,13 @@ struct atm_dev_stats {
|
||||||
/* set interface ESI */
|
/* set interface ESI */
|
||||||
#define ATM_SETESIF _IOW('a',ATMIOC_ITF+13,struct atmif_sioc)
|
#define ATM_SETESIF _IOW('a',ATMIOC_ITF+13,struct atmif_sioc)
|
||||||
/* force interface ESI */
|
/* force interface ESI */
|
||||||
|
#define ATM_ADDLECSADDR _IOW('a', ATMIOC_ITF+14, struct atmif_sioc)
|
||||||
|
/* register a LECS address */
|
||||||
|
#define ATM_DELLECSADDR _IOW('a', ATMIOC_ITF+15, struct atmif_sioc)
|
||||||
|
/* unregister a LECS address */
|
||||||
|
#define ATM_GETLECSADDR _IOW('a', ATMIOC_ITF+16, struct atmif_sioc)
|
||||||
|
/* retrieve LECS address(es) */
|
||||||
|
|
||||||
#define ATM_GETSTAT _IOW('a',ATMIOC_SARCOM+0,struct atmif_sioc)
|
#define ATM_GETSTAT _IOW('a',ATMIOC_SARCOM+0,struct atmif_sioc)
|
||||||
/* get AAL layer statistics */
|
/* get AAL layer statistics */
|
||||||
#define ATM_GETSTATZ _IOW('a',ATMIOC_SARCOM+1,struct atmif_sioc)
|
#define ATM_GETSTATZ _IOW('a',ATMIOC_SARCOM+1,struct atmif_sioc)
|
||||||
|
@ -328,6 +335,8 @@ struct atm_dev_addr {
|
||||||
struct list_head entry; /* next address */
|
struct list_head entry; /* next address */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
|
||||||
|
|
||||||
struct atm_dev {
|
struct atm_dev {
|
||||||
const struct atmdev_ops *ops; /* device operations; NULL if unused */
|
const struct atmdev_ops *ops; /* device operations; NULL if unused */
|
||||||
const struct atmphy_ops *phy; /* PHY operations, may be undefined */
|
const struct atmphy_ops *phy; /* PHY operations, may be undefined */
|
||||||
|
@ -338,6 +347,7 @@ struct atm_dev {
|
||||||
void *phy_data; /* private PHY date */
|
void *phy_data; /* private PHY date */
|
||||||
unsigned long flags; /* device flags (ATM_DF_*) */
|
unsigned long flags; /* device flags (ATM_DF_*) */
|
||||||
struct list_head local; /* local ATM addresses */
|
struct list_head local; /* local ATM addresses */
|
||||||
|
struct list_head lecs; /* LECS ATM addresses learned via ILMI */
|
||||||
unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
|
unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
|
||||||
struct atm_cirange ci_range; /* VPI/VCI range */
|
struct atm_cirange ci_range; /* VPI/VCI range */
|
||||||
struct k_atm_dev_stats stats; /* statistics */
|
struct k_atm_dev_stats stats; /* statistics */
|
||||||
|
|
|
@ -44,31 +44,43 @@ static void notify_sigd(struct atm_dev *dev)
|
||||||
sigd_enq(NULL, as_itf_notify, NULL, &pvc, NULL);
|
sigd_enq(NULL, as_itf_notify, NULL, &pvc, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void atm_reset_addr(struct atm_dev *dev)
|
void atm_reset_addr(struct atm_dev *dev, enum atm_addr_type_t atype)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct atm_dev_addr *this, *p;
|
struct atm_dev_addr *this, *p;
|
||||||
|
struct list_head *head;
|
||||||
|
|
||||||
spin_lock_irqsave(&dev->lock, flags);
|
spin_lock_irqsave(&dev->lock, flags);
|
||||||
list_for_each_entry_safe(this, p, &dev->local, entry) {
|
if (atype == ATM_ADDR_LECS)
|
||||||
|
head = &dev->lecs;
|
||||||
|
else
|
||||||
|
head = &dev->local;
|
||||||
|
list_for_each_entry_safe(this, p, head, entry) {
|
||||||
list_del(&this->entry);
|
list_del(&this->entry);
|
||||||
kfree(this);
|
kfree(this);
|
||||||
}
|
}
|
||||||
spin_unlock_irqrestore(&dev->lock, flags);
|
spin_unlock_irqrestore(&dev->lock, flags);
|
||||||
|
if (head == &dev->local)
|
||||||
notify_sigd(dev);
|
notify_sigd(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
int atm_add_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr)
|
int atm_add_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr,
|
||||||
|
enum atm_addr_type_t atype)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct atm_dev_addr *this;
|
struct atm_dev_addr *this;
|
||||||
|
struct list_head *head;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
error = check_addr(addr);
|
error = check_addr(addr);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
spin_lock_irqsave(&dev->lock, flags);
|
spin_lock_irqsave(&dev->lock, flags);
|
||||||
list_for_each_entry(this, &dev->local, entry) {
|
if (atype == ATM_ADDR_LECS)
|
||||||
|
head = &dev->lecs;
|
||||||
|
else
|
||||||
|
head = &dev->local;
|
||||||
|
list_for_each_entry(this, head, entry) {
|
||||||
if (identical(&this->addr, addr)) {
|
if (identical(&this->addr, addr)) {
|
||||||
spin_unlock_irqrestore(&dev->lock, flags);
|
spin_unlock_irqrestore(&dev->lock, flags);
|
||||||
return -EEXIST;
|
return -EEXIST;
|
||||||
|
@ -80,27 +92,35 @@ int atm_add_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
this->addr = *addr;
|
this->addr = *addr;
|
||||||
list_add(&this->entry, &dev->local);
|
list_add(&this->entry, head);
|
||||||
spin_unlock_irqrestore(&dev->lock, flags);
|
spin_unlock_irqrestore(&dev->lock, flags);
|
||||||
|
if (head == &dev->local)
|
||||||
notify_sigd(dev);
|
notify_sigd(dev);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int atm_del_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr)
|
int atm_del_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr,
|
||||||
|
enum atm_addr_type_t atype)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct atm_dev_addr *this;
|
struct atm_dev_addr *this;
|
||||||
|
struct list_head *head;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
error = check_addr(addr);
|
error = check_addr(addr);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
spin_lock_irqsave(&dev->lock, flags);
|
spin_lock_irqsave(&dev->lock, flags);
|
||||||
list_for_each_entry(this, &dev->local, entry) {
|
if (atype == ATM_ADDR_LECS)
|
||||||
|
head = &dev->lecs;
|
||||||
|
else
|
||||||
|
head = &dev->local;
|
||||||
|
list_for_each_entry(this, head, entry) {
|
||||||
if (identical(&this->addr, addr)) {
|
if (identical(&this->addr, addr)) {
|
||||||
list_del(&this->entry);
|
list_del(&this->entry);
|
||||||
spin_unlock_irqrestore(&dev->lock, flags);
|
spin_unlock_irqrestore(&dev->lock, flags);
|
||||||
kfree(this);
|
kfree(this);
|
||||||
|
if (head == &dev->local)
|
||||||
notify_sigd(dev);
|
notify_sigd(dev);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -110,22 +130,27 @@ int atm_del_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
int atm_get_addr(struct atm_dev *dev, struct sockaddr_atmsvc __user * buf,
|
int atm_get_addr(struct atm_dev *dev, struct sockaddr_atmsvc __user * buf,
|
||||||
size_t size)
|
size_t size, enum atm_addr_type_t atype)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct atm_dev_addr *this;
|
struct atm_dev_addr *this;
|
||||||
|
struct list_head *head;
|
||||||
int total = 0, error;
|
int total = 0, error;
|
||||||
struct sockaddr_atmsvc *tmp_buf, *tmp_bufp;
|
struct sockaddr_atmsvc *tmp_buf, *tmp_bufp;
|
||||||
|
|
||||||
spin_lock_irqsave(&dev->lock, flags);
|
spin_lock_irqsave(&dev->lock, flags);
|
||||||
list_for_each_entry(this, &dev->local, entry)
|
if (atype == ATM_ADDR_LECS)
|
||||||
|
head = &dev->lecs;
|
||||||
|
else
|
||||||
|
head = &dev->local;
|
||||||
|
list_for_each_entry(this, head, entry)
|
||||||
total += sizeof(struct sockaddr_atmsvc);
|
total += sizeof(struct sockaddr_atmsvc);
|
||||||
tmp_buf = tmp_bufp = kmalloc(total, GFP_ATOMIC);
|
tmp_buf = tmp_bufp = kmalloc(total, GFP_ATOMIC);
|
||||||
if (!tmp_buf) {
|
if (!tmp_buf) {
|
||||||
spin_unlock_irqrestore(&dev->lock, flags);
|
spin_unlock_irqrestore(&dev->lock, flags);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
list_for_each_entry(this, &dev->local, entry)
|
list_for_each_entry(this, head, entry)
|
||||||
memcpy(tmp_bufp++, &this->addr, sizeof(struct sockaddr_atmsvc));
|
memcpy(tmp_bufp++, &this->addr, sizeof(struct sockaddr_atmsvc));
|
||||||
spin_unlock_irqrestore(&dev->lock, flags);
|
spin_unlock_irqrestore(&dev->lock, flags);
|
||||||
error = total > size ? -E2BIG : total;
|
error = total > size ? -E2BIG : total;
|
||||||
|
|
|
@ -9,10 +9,12 @@
|
||||||
#include <linux/atm.h>
|
#include <linux/atm.h>
|
||||||
#include <linux/atmdev.h>
|
#include <linux/atmdev.h>
|
||||||
|
|
||||||
|
void atm_reset_addr(struct atm_dev *dev, enum atm_addr_type_t type);
|
||||||
void atm_reset_addr(struct atm_dev *dev);
|
int atm_add_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr,
|
||||||
int atm_add_addr(struct atm_dev *dev,struct sockaddr_atmsvc *addr);
|
enum atm_addr_type_t type);
|
||||||
int atm_del_addr(struct atm_dev *dev,struct sockaddr_atmsvc *addr);
|
int atm_del_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr,
|
||||||
int atm_get_addr(struct atm_dev *dev,struct sockaddr_atmsvc __user *buf,size_t size);
|
enum atm_addr_type_t type);
|
||||||
|
int atm_get_addr(struct atm_dev *dev, struct sockaddr_atmsvc __user *buf,
|
||||||
|
size_t size, enum atm_addr_type_t type);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -40,6 +40,7 @@ static struct atm_dev *__alloc_atm_dev(const char *type)
|
||||||
dev->link_rate = ATM_OC3_PCR;
|
dev->link_rate = ATM_OC3_PCR;
|
||||||
spin_lock_init(&dev->lock);
|
spin_lock_init(&dev->lock);
|
||||||
INIT_LIST_HEAD(&dev->local);
|
INIT_LIST_HEAD(&dev->local);
|
||||||
|
INIT_LIST_HEAD(&dev->lecs);
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
@ -320,10 +321,12 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
|
||||||
error = -EPERM;
|
error = -EPERM;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
atm_reset_addr(dev);
|
atm_reset_addr(dev, ATM_ADDR_LOCAL);
|
||||||
break;
|
break;
|
||||||
case ATM_ADDADDR:
|
case ATM_ADDADDR:
|
||||||
case ATM_DELADDR:
|
case ATM_DELADDR:
|
||||||
|
case ATM_ADDLECSADDR:
|
||||||
|
case ATM_DELLECSADDR:
|
||||||
if (!capable(CAP_NET_ADMIN)) {
|
if (!capable(CAP_NET_ADMIN)) {
|
||||||
error = -EPERM;
|
error = -EPERM;
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -335,14 +338,21 @@ int atm_dev_ioctl(unsigned int cmd, void __user *arg)
|
||||||
error = -EFAULT;
|
error = -EFAULT;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (cmd == ATM_ADDADDR)
|
if (cmd == ATM_ADDADDR || cmd == ATM_ADDLECSADDR)
|
||||||
error = atm_add_addr(dev, &addr);
|
error = atm_add_addr(dev, &addr,
|
||||||
|
(cmd == ATM_ADDADDR ?
|
||||||
|
ATM_ADDR_LOCAL : ATM_ADDR_LECS));
|
||||||
else
|
else
|
||||||
error = atm_del_addr(dev, &addr);
|
error = atm_del_addr(dev, &addr,
|
||||||
|
(cmd == ATM_DELADDR ?
|
||||||
|
ATM_ADDR_LOCAL : ATM_ADDR_LECS));
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
case ATM_GETADDR:
|
case ATM_GETADDR:
|
||||||
error = atm_get_addr(dev, buf, len);
|
case ATM_GETLECSADDR:
|
||||||
|
error = atm_get_addr(dev, buf, len,
|
||||||
|
(cmd == ATM_GETADDR ?
|
||||||
|
ATM_ADDR_LOCAL : ATM_ADDR_LECS));
|
||||||
if (error < 0)
|
if (error < 0)
|
||||||
goto done;
|
goto done;
|
||||||
size = error;
|
size = error;
|
||||||
|
|
Loading…
Reference in a new issue