History

net: Add support for filtering neigh dump by master device

Add support for filtering neighbor dumps by master device by adding the NDA_MASTER attribute to the dump request. A new netlink flag, NLM_F_DUMP_FILTERED, is added to indicate the kernel supports the request and output is filtered as requested.

David Ahern committed 11 years ago

Commit 21fdd091 parent 51723932 files · +32 −1Browse files

Unified · Split

2 files
  1. include/uapi/linux/netlink.h +1 −0
  2. net/core/neighbour.c +31 −1
include/uapi/linux/netlink.h+1−0
@@ -54,6 +54,7 @@ struct nlmsghdr { · 53 unmodified lines
5454 #define NLM_F_ACK 4 /* Reply with ack, with zero or error code */
5555 #define NLM_F_ECHO 8 /* Echo this request */
5656 #define NLM_F_DUMP_INTR 16 /* Dump was inconsistent due to sequence change */
57+#define NLM_F_DUMP_FILTERED 32 /* Dump was filtered as requested */
5758
5859 /* Modifiers to GET request */
5960 #define NLM_F_ROOT 0x100 /* specify tree root */
net/core/neighbour.c+31−1
@@ -2235,14 +2235,42 @@ static void neigh_update_notify(struct neighbour *neigh) · 2234 unmodified lines
22352235 __neigh_notify(neigh, RTM_NEWNEIGH, 0);
22362236 }
22372237
2238+static bool neigh_master_filtered(struct net_device *dev, int master_idx)
2239+{
2240+ struct net_device *master;
2241+
2242+ if (!master_idx)
2243+ return false;
2244+
2245+ master = netdev_master_upper_dev_get(dev);
2246+ if (!master || master->ifindex != master_idx)
2247+ return true;
2248+
2249+ return false;
2250+}
2251+
22382252 static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
22392253 struct netlink_callback *cb)
22402254 {
22412255 struct net *net = sock_net(skb->sk);
2256+ const struct nlmsghdr *nlh = cb->nlh;
2257+ struct nlattr *tb[NDA_MAX + 1];
22422258 struct neighbour *n;
22432259 int rc, h, s_h = cb->args[1];
22442260 int idx, s_idx = idx = cb->args[2];
22452261 struct neigh_hash_table *nht;
2262+ int filter_master_idx = 0;
2263+ unsigned int flags = NLM_F_MULTI;
2264+ int err;
2265+
2266+ err = nlmsg_parse(nlh, sizeof(struct ndmsg), tb, NDA_MAX, NULL);
2267+ if (!err) {
2268+ if (tb[NDA_MASTER])
2269+ filter_master_idx = nla_get_u32(tb[NDA_MASTER]);
2270+
2271+ if (filter_master_idx)
2272+ flags |= NLM_F_DUMP_FILTERED;
2273+ }
22462274
22472275 rcu_read_lock_bh();
22482276 nht = rcu_dereference_bh(tbl->nht);
@@ -2255,12 +2283,14 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb, · 6 unmodified lines
22552283 n = rcu_dereference_bh(n->next)) {
22562284 if (!net_eq(dev_net(n->dev), net))
22572285 continue;
2286+ if (neigh_master_filtered(n->dev, filter_master_idx))
2287+ continue;
22582288 if (idx < s_idx)
22592289 goto next;
22602290 if (neigh_fill_info(skb, n, NETLINK_CB(cb->skb).portid,
22612291 cb->nlh->nlmsg_seq,
22622292 RTM_NEWNEIGH,
2263− NLM_F_MULTI) < 0) {
2293+ flags) < 0) {
22642294 rc = -1;
22652295 goto out;
22662296 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t