diff options
author | Nicolas Dichtel <nicolas.dichtel@6wind.com> | 2012-10-25 18:28:53 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-10-28 19:05:00 -0400 |
commit | 9e5511106f99f293ad4a55e1d35c2e909c0c2e60 (patch) | |
tree | 873b3999d0ace885fc85b7f8f4d545a06e555d60 /net/ipv4/devinet.c | |
parent | edc9e748934cf406cab708ca5dda7bd3c0f0a1db (diff) |
rtnl/ipv4: add support of RTM_GETNETCONF
This message allows to get the devconf for an interface.
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/devinet.c')
-rw-r--r-- | net/ipv4/devinet.c | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 020fdd2e6e19..f8b1e0494d75 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c | |||
@@ -1448,7 +1448,8 @@ static int inet_netconf_msgsize_devconf(int type) | |||
1448 | int size = NLMSG_ALIGN(sizeof(struct netconfmsg)) | 1448 | int size = NLMSG_ALIGN(sizeof(struct netconfmsg)) |
1449 | + nla_total_size(4); /* NETCONFA_IFINDEX */ | 1449 | + nla_total_size(4); /* NETCONFA_IFINDEX */ |
1450 | 1450 | ||
1451 | if (type == NETCONFA_FORWARDING) | 1451 | /* type -1 is used for ALL */ |
1452 | if (type == -1 || type == NETCONFA_FORWARDING) | ||
1452 | size += nla_total_size(4); | 1453 | size += nla_total_size(4); |
1453 | 1454 | ||
1454 | return size; | 1455 | return size; |
@@ -1473,7 +1474,8 @@ static int inet_netconf_fill_devconf(struct sk_buff *skb, int ifindex, | |||
1473 | if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0) | 1474 | if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0) |
1474 | goto nla_put_failure; | 1475 | goto nla_put_failure; |
1475 | 1476 | ||
1476 | if (type == NETCONFA_FORWARDING && | 1477 | /* type -1 is used for ALL */ |
1478 | if ((type == -1 || type == NETCONFA_FORWARDING) && | ||
1477 | nla_put_s32(skb, NETCONFA_FORWARDING, | 1479 | nla_put_s32(skb, NETCONFA_FORWARDING, |
1478 | IPV4_DEVCONF(*devconf, FORWARDING)) < 0) | 1480 | IPV4_DEVCONF(*devconf, FORWARDING)) < 0) |
1479 | goto nla_put_failure; | 1481 | goto nla_put_failure; |
@@ -1510,6 +1512,73 @@ errout: | |||
1510 | rtnl_set_sk_err(net, RTNLGRP_IPV4_NETCONF, err); | 1512 | rtnl_set_sk_err(net, RTNLGRP_IPV4_NETCONF, err); |
1511 | } | 1513 | } |
1512 | 1514 | ||
1515 | static const struct nla_policy devconf_ipv4_policy[NETCONFA_MAX+1] = { | ||
1516 | [NETCONFA_IFINDEX] = { .len = sizeof(int) }, | ||
1517 | [NETCONFA_FORWARDING] = { .len = sizeof(int) }, | ||
1518 | }; | ||
1519 | |||
1520 | static int inet_netconf_get_devconf(struct sk_buff *in_skb, | ||
1521 | struct nlmsghdr *nlh, | ||
1522 | void *arg) | ||
1523 | { | ||
1524 | struct net *net = sock_net(in_skb->sk); | ||
1525 | struct nlattr *tb[NETCONFA_MAX+1]; | ||
1526 | struct netconfmsg *ncm; | ||
1527 | struct sk_buff *skb; | ||
1528 | struct ipv4_devconf *devconf; | ||
1529 | struct in_device *in_dev; | ||
1530 | struct net_device *dev; | ||
1531 | int ifindex; | ||
1532 | int err; | ||
1533 | |||
1534 | err = nlmsg_parse(nlh, sizeof(*ncm), tb, NETCONFA_MAX, | ||
1535 | devconf_ipv4_policy); | ||
1536 | if (err < 0) | ||
1537 | goto errout; | ||
1538 | |||
1539 | err = EINVAL; | ||
1540 | if (!tb[NETCONFA_IFINDEX]) | ||
1541 | goto errout; | ||
1542 | |||
1543 | ifindex = nla_get_s32(tb[NETCONFA_IFINDEX]); | ||
1544 | switch (ifindex) { | ||
1545 | case NETCONFA_IFINDEX_ALL: | ||
1546 | devconf = net->ipv4.devconf_all; | ||
1547 | break; | ||
1548 | case NETCONFA_IFINDEX_DEFAULT: | ||
1549 | devconf = net->ipv4.devconf_dflt; | ||
1550 | break; | ||
1551 | default: | ||
1552 | dev = __dev_get_by_index(net, ifindex); | ||
1553 | if (dev == NULL) | ||
1554 | goto errout; | ||
1555 | in_dev = __in_dev_get_rtnl(dev); | ||
1556 | if (in_dev == NULL) | ||
1557 | goto errout; | ||
1558 | devconf = &in_dev->cnf; | ||
1559 | break; | ||
1560 | } | ||
1561 | |||
1562 | err = -ENOBUFS; | ||
1563 | skb = nlmsg_new(inet_netconf_msgsize_devconf(-1), GFP_ATOMIC); | ||
1564 | if (skb == NULL) | ||
1565 | goto errout; | ||
1566 | |||
1567 | err = inet_netconf_fill_devconf(skb, ifindex, devconf, | ||
1568 | NETLINK_CB(in_skb).portid, | ||
1569 | nlh->nlmsg_seq, RTM_NEWNETCONF, 0, | ||
1570 | -1); | ||
1571 | if (err < 0) { | ||
1572 | /* -EMSGSIZE implies BUG in inet_netconf_msgsize_devconf() */ | ||
1573 | WARN_ON(err == -EMSGSIZE); | ||
1574 | kfree_skb(skb); | ||
1575 | goto errout; | ||
1576 | } | ||
1577 | err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid); | ||
1578 | errout: | ||
1579 | return err; | ||
1580 | } | ||
1581 | |||
1513 | #ifdef CONFIG_SYSCTL | 1582 | #ifdef CONFIG_SYSCTL |
1514 | 1583 | ||
1515 | static void devinet_copy_dflt_conf(struct net *net, int i) | 1584 | static void devinet_copy_dflt_conf(struct net *net, int i) |
@@ -1894,5 +1963,7 @@ void __init devinet_init(void) | |||
1894 | rtnl_register(PF_INET, RTM_NEWADDR, inet_rtm_newaddr, NULL, NULL); | 1963 | rtnl_register(PF_INET, RTM_NEWADDR, inet_rtm_newaddr, NULL, NULL); |
1895 | rtnl_register(PF_INET, RTM_DELADDR, inet_rtm_deladdr, NULL, NULL); | 1964 | rtnl_register(PF_INET, RTM_DELADDR, inet_rtm_deladdr, NULL, NULL); |
1896 | rtnl_register(PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr, NULL); | 1965 | rtnl_register(PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr, NULL); |
1966 | rtnl_register(PF_INET, RTM_GETNETCONF, inet_netconf_get_devconf, | ||
1967 | NULL, NULL); | ||
1897 | } | 1968 | } |
1898 | 1969 | ||