From: Patrick McHardy <kaber@trash.net>
To: netdev@vger.kernel.org
Cc: Patrick McHardy <kaber@trash.net>
Subject: [NET 02/05]: dev: introduce generic net_device address lists
Date: Fri, 22 Jun 2007 14:24:09 +0200 (MEST) [thread overview]
Message-ID: <20070622122333.15215.96140.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20070622122330.15215.47821.sendpatchset@localhost.localdomain>
[NET]: dev: introduce generic net_device address lists
Introduce struct dev_addr_list and list maintenance functions
based on dev_mc_list and the related functions. This will be
used by follow-up patches for both multicast and secondary
unicast addresses.
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
commit 6d8fd140951de7cc8faab4922dba74dd1db3cae5
tree b80412116a867d544808f140e76cdf22bbc8b248
parent cdf660f0bd4cca9d2cbe86a31adc60d6fa8a60ec
author Patrick McHardy <kaber@trash.net> Fri, 22 Jun 2007 03:25:26 +0200
committer Patrick McHardy <kaber@trash.net> Fri, 22 Jun 2007 03:25:26 +0200
include/linux/netdevice.h | 11 +++++++
net/core/dev.c | 69 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index e7913ee..3785a8a 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -177,6 +177,14 @@ struct netif_rx_stats
DECLARE_PER_CPU(struct netif_rx_stats, netdev_rx_stat);
+struct dev_addr_list
+{
+ struct dev_addr_list *next;
+ u8 da_addr[MAX_ADDR_LEN];
+ u8 da_addrlen;
+ int da_users;
+ int da_gusers;
+};
/*
* We tag multicasts with these structures.
@@ -1004,6 +1012,9 @@ extern void dev_mc_upload(struct net_device *dev);
extern int dev_mc_delete(struct net_device *dev, void *addr, int alen, int all);
extern int dev_mc_add(struct net_device *dev, void *addr, int alen, int newonly);
extern void dev_mc_discard(struct net_device *dev);
+extern int __dev_addr_delete(struct dev_addr_list **list, void *addr, int alen, int all);
+extern int __dev_addr_add(struct dev_addr_list **list, void *addr, int alen, int newonly);
+extern void __dev_addr_discard(struct dev_addr_list **list);
extern void dev_set_promiscuity(struct net_device *dev, int inc);
extern void dev_set_allmulti(struct net_device *dev, int inc);
extern void netdev_state_change(struct net_device *dev);
diff --git a/net/core/dev.c b/net/core/dev.c
index 2609062..1496715 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2551,6 +2551,75 @@ void dev_set_allmulti(struct net_device *dev, int inc)
dev_mc_upload(dev);
}
+int __dev_addr_delete(struct dev_addr_list **list, void *addr, int alen,
+ int glbl)
+{
+ struct dev_addr_list *da;
+
+ for (; (da = *list) != NULL; list = &da->next) {
+ if (memcmp(da->da_addr, addr, da->da_addrlen) == 0 &&
+ alen == da->da_addrlen) {
+ if (glbl) {
+ int old_glbl = da->da_gusers;
+ da->da_gusers = 0;
+ if (old_glbl == 0)
+ break;
+ }
+ if (--da->da_users)
+ return 0;
+
+ *list = da->next;
+ kfree(da);
+ return 0;
+ }
+ }
+ return -ENOENT;
+}
+
+int __dev_addr_add(struct dev_addr_list **list, void *addr, int alen, int glbl)
+{
+ struct dev_addr_list *da;
+
+ for (da = *list; da != NULL; da = da->next) {
+ if (memcmp(da->da_addr, addr, da->da_addrlen) == 0 &&
+ da->da_addrlen == alen) {
+ if (glbl) {
+ int old_glbl = da->da_gusers;
+ da->da_gusers = 1;
+ if (old_glbl)
+ return 0;
+ }
+ da->da_users++;
+ return 0;
+ }
+ }
+
+ da = kmalloc(sizeof(*da), GFP_ATOMIC);
+ if (da == NULL)
+ return -ENOMEM;
+ memcpy(da->da_addr, addr, alen);
+ da->da_addrlen = alen;
+ da->da_users = 1;
+ da->da_gusers = glbl ? 1 : 0;
+ da->next = *list;
+ *list = da;
+ return 0;
+}
+
+void __dev_addr_discard(struct dev_addr_list **list)
+{
+ struct dev_addr_list *tmp;
+
+ while (*list != NULL) {
+ tmp = *list;
+ *list = tmp->next;
+ if (tmp->da_users > tmp->da_gusers)
+ printk("__dev_addr_discard: address leakage! "
+ "da_users=%d\n", tmp->da_users);
+ kfree(tmp);
+ }
+}
+
unsigned dev_get_flags(const struct net_device *dev)
{
unsigned flags;
next prev parent reply other threads:[~2007-06-22 12:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-22 12:24 [NET 00/05]: Secondary unicast address support v2 Patrick McHardy
2007-06-22 12:24 ` [NET 01/05]: dev_mcast: unexport dev_mc_upload Patrick McHardy
2007-06-27 8:25 ` David Miller
2007-06-22 12:24 ` Patrick McHardy [this message]
2007-06-27 8:26 ` [NET 02/05]: dev: introduce generic net_device address lists David Miller
2007-06-22 12:24 ` [NET 03/05]: dev_mcast: switch to " Patrick McHardy
2007-06-27 8:27 ` David Miller
2007-06-22 12:24 ` [NET 04/05]: dev: secondary unicast address support Patrick McHardy
2007-06-27 8:28 ` David Miller
2007-06-27 8:30 ` Patrick McHardy
2007-06-27 8:55 ` David Miller
2007-06-22 12:24 ` [E1000 05/05]: Secondary " Patrick McHardy
2007-06-25 19:01 ` Kok, Auke
2007-06-25 19:05 ` Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070622122333.15215.96140.sendpatchset@localhost.localdomain \
--to=kaber@trash.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.