diff options
author | Thomas Graf <tgraf@suug.ch> | 2006-08-07 20:56:37 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-09-22 17:54:00 -0400 |
commit | 8b8aec508302d4e63fd88f47894805115277f70f (patch) | |
tree | 79972eb86fb0a01552bd6ed010126040aa32c34e /net/core/neighbour.c | |
parent | 5208debd0f1da07bbb350f8b0b142775d4f002ea (diff) |
[NEIGH]: Convert neighbour dumping to new netlink api
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/neighbour.c')
-rw-r--r-- | net/core/neighbour.c | 106 |
1 files changed, 51 insertions, 55 deletions
diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 6036f43c1fd6..5490afd23b82 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c | |||
@@ -1901,48 +1901,49 @@ out: | |||
1901 | return skb->len; | 1901 | return skb->len; |
1902 | } | 1902 | } |
1903 | 1903 | ||
1904 | static int neigh_fill_info(struct sk_buff *skb, struct neighbour *n, | 1904 | static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh, |
1905 | u32 pid, u32 seq, int event, unsigned int flags) | 1905 | u32 pid, u32 seq, int type, unsigned int flags) |
1906 | { | 1906 | { |
1907 | unsigned long now = jiffies; | 1907 | unsigned long now = jiffies; |
1908 | unsigned char *b = skb->tail; | ||
1909 | struct nda_cacheinfo ci; | 1908 | struct nda_cacheinfo ci; |
1910 | int locked = 0; | 1909 | struct nlmsghdr *nlh; |
1911 | u32 probes; | 1910 | struct ndmsg *ndm; |
1912 | struct nlmsghdr *nlh = NLMSG_NEW(skb, pid, seq, event, | 1911 | |
1913 | sizeof(struct ndmsg), flags); | 1912 | nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), flags); |
1914 | struct ndmsg *ndm = NLMSG_DATA(nlh); | 1913 | if (nlh == NULL) |
1914 | return -ENOBUFS; | ||
1915 | 1915 | ||
1916 | ndm->ndm_family = n->ops->family; | 1916 | ndm = nlmsg_data(nlh); |
1917 | ndm->ndm_family = neigh->ops->family; | ||
1917 | ndm->ndm_pad1 = 0; | 1918 | ndm->ndm_pad1 = 0; |
1918 | ndm->ndm_pad2 = 0; | 1919 | ndm->ndm_pad2 = 0; |
1919 | ndm->ndm_flags = n->flags; | 1920 | ndm->ndm_flags = neigh->flags; |
1920 | ndm->ndm_type = n->type; | 1921 | ndm->ndm_type = neigh->type; |
1921 | ndm->ndm_ifindex = n->dev->ifindex; | 1922 | ndm->ndm_ifindex = neigh->dev->ifindex; |
1922 | RTA_PUT(skb, NDA_DST, n->tbl->key_len, n->primary_key); | ||
1923 | read_lock_bh(&n->lock); | ||
1924 | locked = 1; | ||
1925 | ndm->ndm_state = n->nud_state; | ||
1926 | if (n->nud_state & NUD_VALID) | ||
1927 | RTA_PUT(skb, NDA_LLADDR, n->dev->addr_len, n->ha); | ||
1928 | ci.ndm_used = now - n->used; | ||
1929 | ci.ndm_confirmed = now - n->confirmed; | ||
1930 | ci.ndm_updated = now - n->updated; | ||
1931 | ci.ndm_refcnt = atomic_read(&n->refcnt) - 1; | ||
1932 | probes = atomic_read(&n->probes); | ||
1933 | read_unlock_bh(&n->lock); | ||
1934 | locked = 0; | ||
1935 | RTA_PUT(skb, NDA_CACHEINFO, sizeof(ci), &ci); | ||
1936 | RTA_PUT(skb, NDA_PROBES, sizeof(probes), &probes); | ||
1937 | nlh->nlmsg_len = skb->tail - b; | ||
1938 | return skb->len; | ||
1939 | 1923 | ||
1940 | nlmsg_failure: | 1924 | NLA_PUT(skb, NDA_DST, neigh->tbl->key_len, neigh->primary_key); |
1941 | rtattr_failure: | 1925 | |
1942 | if (locked) | 1926 | read_lock_bh(&neigh->lock); |
1943 | read_unlock_bh(&n->lock); | 1927 | ndm->ndm_state = neigh->nud_state; |
1944 | skb_trim(skb, b - skb->data); | 1928 | if ((neigh->nud_state & NUD_VALID) && |
1945 | return -1; | 1929 | nla_put(skb, NDA_LLADDR, neigh->dev->addr_len, neigh->ha) < 0) { |
1930 | read_unlock_bh(&neigh->lock); | ||
1931 | goto nla_put_failure; | ||
1932 | } | ||
1933 | |||
1934 | ci.ndm_used = now - neigh->used; | ||
1935 | ci.ndm_confirmed = now - neigh->confirmed; | ||
1936 | ci.ndm_updated = now - neigh->updated; | ||
1937 | ci.ndm_refcnt = atomic_read(&neigh->refcnt) - 1; | ||
1938 | read_unlock_bh(&neigh->lock); | ||
1939 | |||
1940 | NLA_PUT_U32(skb, NDA_PROBES, atomic_read(&neigh->probes)); | ||
1941 | NLA_PUT(skb, NDA_CACHEINFO, sizeof(ci), &ci); | ||
1942 | |||
1943 | return nlmsg_end(skb, nlh); | ||
1944 | |||
1945 | nla_put_failure: | ||
1946 | return nlmsg_cancel(skb, nlh); | ||
1946 | } | 1947 | } |
1947 | 1948 | ||
1948 | 1949 | ||
@@ -1986,7 +1987,7 @@ int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb) | |||
1986 | int t, family, s_t; | 1987 | int t, family, s_t; |
1987 | 1988 | ||
1988 | read_lock(&neigh_tbl_lock); | 1989 | read_lock(&neigh_tbl_lock); |
1989 | family = ((struct rtgenmsg *)NLMSG_DATA(cb->nlh))->rtgen_family; | 1990 | family = ((struct rtgenmsg *) nlmsg_data(cb->nlh))->rtgen_family; |
1990 | s_t = cb->args[0]; | 1991 | s_t = cb->args[0]; |
1991 | 1992 | ||
1992 | for (tbl = neigh_tables, t = 0; tbl; tbl = tbl->next, t++) { | 1993 | for (tbl = neigh_tables, t = 0; tbl; tbl = tbl->next, t++) { |
@@ -2367,39 +2368,34 @@ static struct file_operations neigh_stat_seq_fops = { | |||
2367 | #ifdef CONFIG_ARPD | 2368 | #ifdef CONFIG_ARPD |
2368 | void neigh_app_ns(struct neighbour *n) | 2369 | void neigh_app_ns(struct neighbour *n) |
2369 | { | 2370 | { |
2370 | struct nlmsghdr *nlh; | 2371 | struct sk_buff *skb; |
2371 | int size = NLMSG_SPACE(sizeof(struct ndmsg) + 256); | ||
2372 | struct sk_buff *skb = alloc_skb(size, GFP_ATOMIC); | ||
2373 | 2372 | ||
2374 | if (!skb) | 2373 | skb = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); |
2374 | if (skb == NULL) | ||
2375 | return; | 2375 | return; |
2376 | 2376 | ||
2377 | if (neigh_fill_info(skb, n, 0, 0, RTM_GETNEIGH, 0) < 0) { | 2377 | if (neigh_fill_info(skb, n, 0, 0, RTM_GETNEIGH, NLM_F_REQUEST) <= 0) |
2378 | kfree_skb(skb); | 2378 | kfree_skb(skb); |
2379 | return; | 2379 | else { |
2380 | NETLINK_CB(skb).dst_group = RTNLGRP_NEIGH; | ||
2381 | netlink_broadcast(rtnl, skb, 0, RTNLGRP_NEIGH, GFP_ATOMIC); | ||
2380 | } | 2382 | } |
2381 | nlh = (struct nlmsghdr *)skb->data; | ||
2382 | nlh->nlmsg_flags = NLM_F_REQUEST; | ||
2383 | NETLINK_CB(skb).dst_group = RTNLGRP_NEIGH; | ||
2384 | netlink_broadcast(rtnl, skb, 0, RTNLGRP_NEIGH, GFP_ATOMIC); | ||
2385 | } | 2383 | } |
2386 | 2384 | ||
2387 | static void neigh_app_notify(struct neighbour *n) | 2385 | static void neigh_app_notify(struct neighbour *n) |
2388 | { | 2386 | { |
2389 | struct nlmsghdr *nlh; | 2387 | struct sk_buff *skb; |
2390 | int size = NLMSG_SPACE(sizeof(struct ndmsg) + 256); | ||
2391 | struct sk_buff *skb = alloc_skb(size, GFP_ATOMIC); | ||
2392 | 2388 | ||
2393 | if (!skb) | 2389 | skb = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); |
2390 | if (skb == NULL) | ||
2394 | return; | 2391 | return; |
2395 | 2392 | ||
2396 | if (neigh_fill_info(skb, n, 0, 0, RTM_NEWNEIGH, 0) < 0) { | 2393 | if (neigh_fill_info(skb, n, 0, 0, RTM_NEWNEIGH, 0) <= 0) |
2397 | kfree_skb(skb); | 2394 | kfree_skb(skb); |
2398 | return; | 2395 | else { |
2396 | NETLINK_CB(skb).dst_group = RTNLGRP_NEIGH; | ||
2397 | netlink_broadcast(rtnl, skb, 0, RTNLGRP_NEIGH, GFP_ATOMIC); | ||
2399 | } | 2398 | } |
2400 | nlh = (struct nlmsghdr *)skb->data; | ||
2401 | NETLINK_CB(skb).dst_group = RTNLGRP_NEIGH; | ||
2402 | netlink_broadcast(rtnl, skb, 0, RTNLGRP_NEIGH, GFP_ATOMIC); | ||
2403 | } | 2399 | } |
2404 | 2400 | ||
2405 | #endif /* CONFIG_ARPD */ | 2401 | #endif /* CONFIG_ARPD */ |