Commit 04561c1f authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

[IPv6] iflink: Convert IPv6's RTM_GETLINK to use the new netlink api

By replacing the current method of exporting the device configuration
which included allocating a temporary buffer, copying ipv6_devconf
into it and copying that buffer into the message with a method that
uses nla_reserve() allowing to copy the device configuration directly
into the skb data buffer, a GFP_ATOMIC allocation could be removed.
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a928630a
...@@ -3360,6 +3360,8 @@ static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa) ...@@ -3360,6 +3360,8 @@ static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa)
static void inline ipv6_store_devconf(struct ipv6_devconf *cnf, static void inline ipv6_store_devconf(struct ipv6_devconf *cnf,
__s32 *array, int bytes) __s32 *array, int bytes)
{ {
BUG_ON(bytes < (DEVCONF_MAX * 4));
memset(array, 0, bytes); memset(array, 0, bytes);
array[DEVCONF_FORWARDING] = cnf->forwarding; array[DEVCONF_FORWARDING] = cnf->forwarding;
array[DEVCONF_HOPLIMIT] = cnf->hop_limit; array[DEVCONF_HOPLIMIT] = cnf->hop_limit;
...@@ -3410,65 +3412,58 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, ...@@ -3410,65 +3412,58 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
u32 pid, u32 seq, int event, unsigned int flags) u32 pid, u32 seq, int event, unsigned int flags)
{ {
struct net_device *dev = idev->dev; struct net_device *dev = idev->dev;
__s32 *array = NULL; struct nlattr *conf;
struct ifinfomsg *r; struct ifinfomsg *hdr;
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
unsigned char *b = skb->tail; void *protoinfo;
struct rtattr *subattr;
__u32 mtu = dev->mtu;
struct ifla_cacheinfo ci; struct ifla_cacheinfo ci;
nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*r), flags); nlh = nlmsg_put(skb, pid, seq, event, sizeof(*hdr), flags);
r = NLMSG_DATA(nlh); if (nlh == NULL)
r->ifi_family = AF_INET6; return -ENOBUFS;
r->__ifi_pad = 0;
r->ifi_type = dev->type;
r->ifi_index = dev->ifindex;
r->ifi_flags = dev_get_flags(dev);
r->ifi_change = 0;
RTA_PUT(skb, IFLA_IFNAME, strlen(dev->name)+1, dev->name); hdr = nlmsg_data(nlh);
hdr->ifi_family = AF_INET6;
hdr->__ifi_pad = 0;
hdr->ifi_type = dev->type;
hdr->ifi_index = dev->ifindex;
hdr->ifi_flags = dev_get_flags(dev);
hdr->ifi_change = 0;
NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name);
if (dev->addr_len) if (dev->addr_len)
RTA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr); NLA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr);
RTA_PUT(skb, IFLA_MTU, sizeof(mtu), &mtu); NLA_PUT_U32(skb, IFLA_MTU, dev->mtu);
if (dev->ifindex != dev->iflink) if (dev->ifindex != dev->iflink)
RTA_PUT(skb, IFLA_LINK, sizeof(int), &dev->iflink); NLA_PUT_U32(skb, IFLA_LINK, dev->iflink);
subattr = (struct rtattr*)skb->tail;
RTA_PUT(skb, IFLA_PROTINFO, 0, NULL); protoinfo = nla_nest_start(skb, IFLA_PROTINFO);
if (protoinfo == NULL)
goto nla_put_failure;
/* return the device flags */ NLA_PUT_U32(skb, IFLA_INET6_FLAGS, idev->if_flags);
RTA_PUT(skb, IFLA_INET6_FLAGS, sizeof(__u32), &idev->if_flags);
/* return interface cacheinfo */
ci.max_reasm_len = IPV6_MAXPLEN; ci.max_reasm_len = IPV6_MAXPLEN;
ci.tstamp = (__u32)(TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) / HZ * 100 ci.tstamp = (__u32)(TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) / HZ * 100
+ TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ); + TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
ci.reachable_time = idev->nd_parms->reachable_time; ci.reachable_time = idev->nd_parms->reachable_time;
ci.retrans_time = idev->nd_parms->retrans_time; ci.retrans_time = idev->nd_parms->retrans_time;
RTA_PUT(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci); NLA_PUT(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci);
/* return the device sysctl params */ conf = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32));
if ((array = kmalloc(DEVCONF_MAX * sizeof(*array), GFP_ATOMIC)) == NULL) if (conf == NULL)
goto rtattr_failure; goto nla_put_failure;
ipv6_store_devconf(&idev->cnf, array, DEVCONF_MAX * sizeof(*array)); ipv6_store_devconf(&idev->cnf, nla_data(conf), nla_len(conf));
RTA_PUT(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(*array), array);
/* XXX - Statistics/MC not implemented */ /* XXX - Statistics/MC not implemented */
subattr->rta_len = skb->tail - (u8*)subattr;
nlh->nlmsg_len = skb->tail - b; nla_nest_end(skb, protoinfo);
kfree(array); return nlmsg_end(skb, nlh);
return skb->len;
nlmsg_failure: nla_put_failure:
rtattr_failure: return nlmsg_cancel(skb, nlh);
kfree(array);
skb_trim(skb, b - skb->data);
return -1;
} }
static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment