: Add rtnl_put_cacheinfo() to unify some code
Subsystems (3)
IPv4, IPv6, and DECNet all use struct rta_cacheinfo in a similiar way, therefore rtnl_put_cacheinfo() is added to reuse code.
Signed-off-by Thomas Graf <[email protected]>
net/core/rtnetlink.c +18 -0
@@ -212,6 +212,24 @@return nla_nest_cancel (skb, mx); } +int rtnl_put_cacheinfo (struct sk_buff *skb,struct dst_entry *dst,u32 id, +u32 ts,u32 tsage,long expires,u32 error) +{ +struct rta_cacheinfo ci = { + .rta_lastuse =jiffies_to_clock_t (jiffies - dst->lastuse), + .rta_used = dst->__use, + .rta_clntref =atomic_read (&(dst->__refcnt)), + .rta_error = error, + .rta_id = id, + .rta_ts = ts, + .rta_tsage = tsage, + }; + +if (expires) + ci.rta_expires =jiffies_to_clock_t (expires); + +return nla_put (skb,RTA_CACHEINFO ,sizeof (ci), &ci); +}static void set_operstate (struct net_device *dev,unsigned char transition) {
include/linux/rtnetlink.h +3 -0
@@ -585,6 +585,9 @@ struct nlmsghdr *nlh, gfp_t flags);extern void rtnl_set_sk_err (u32 group,int error);extern int rtnetlink_put_metrics (struct sk_buff *skb,u32 *metrics); +extern int rtnl_put_cacheinfo (struct sk_buff *skb,struct dst_entry *dst, +u32 id,u32 ts,u32 tsage,long expires, +u32 error);extern void __rta_fill (struct sk_buff *skb,int attrtype,int attrlen,const void *data);
net/ipv4/route.c +11 -15
@@ -2629,7 +2629,8 @@struct rtable *rt = (struct rtable *)skb->dst;struct rtmsg *r;struct nlmsghdr *nlh; -struct rta_cacheinfo ci; +long expires; +u32 id =0 , ts =0 , tsage =0 , error; nlh =nlmsg_put (skb, pid, seq, event,sizeof (*r), flags);if (nlh ==NULL )
@@ -2676,20 +2677,13 @@if (rtnetlink_put_metrics (skb, rt->u.dst.metrics) <0 ) goto nla_put_failure; - ci.rta_lastuse =jiffies_to_clock_t (jiffies - rt->u.dst.lastuse); - ci.rta_used = rt->u.dst.__use; - ci.rta_clntref =atomic_read (&rt->u.dst.__refcnt); -if (rt->u.dst.expires) - ci.rta_expires =jiffies_to_clock_t (rt->u.dst.expires - jiffies); -else - ci.rta_expires =0 ; - ci.rta_error = rt->u.dst.error; - ci.rta_id = ci.rta_ts = ci.rta_tsage =0 ; + error = rt->u.dst.error; + expires = rt->u.dst.expires ? rt->u.dst.expires - jiffies :0 ;if (rt->peer) { - ci.rta_id = rt->peer->ip_id_count; + id = rt->peer->ip_id_count;if (rt->peer->tcp_ts_stamp) { - ci.rta_ts = rt->peer->tcp_ts; - ci.rta_tsage = xtime.tv_sec - rt->peer->tcp_ts_stamp; + ts = rt->peer->tcp_ts; + tsage = xtime.tv_sec - rt->peer->tcp_ts_stamp; } }
@@ -2708,7 +2702,7 @@ }else {if (err == -EMSGSIZE ) goto nla_put_failure; - ci.rta_error = err; + error = err; } } }else
@@ -2716,7 +2710,9 @@NLA_PUT_U32 (skb,RTA_IIF , rt->fl.iif); } -NLA_PUT (skb,RTA_CACHEINFO ,sizeof (ci), &ci); +if (rtnl_put_cacheinfo (skb, &rt->u.dst, id, ts, tsage, + expires, error) <0 ) + goto nla_put_failure;return nlmsg_end (skb, nlh);
net/ipv6/route.c +6 -13
@@ -2026,7 +2026,7 @@ {struct rtmsg *rtm;struct nlmsghdr *nlh; -struct rta_cacheinfo ci; +long expires;u32 table;if (prefix) {/* user wants prefix routes only */
@@ -2100,18 +2100,11 @@NLA_PUT_U32 (skb,RTA_OIF , rt->rt6i_dev->ifindex);NLA_PUT_U32 (skb,RTA_PRIORITY , rt->rt6i_metric); - ci.rta_lastuse =jiffies_to_clock_t (jiffies - rt->u.dst.lastuse); -if (rt->rt6i_expires) - ci.rta_expires =jiffies_to_clock_t (rt->rt6i_expires - jiffies); -else - ci.rta_expires =0 ; - ci.rta_used = rt->u.dst.__use; - ci.rta_clntref =atomic_read (&rt->u.dst.__refcnt); - ci.rta_error = rt->u.dst.error; - ci.rta_id =0 ; - ci.rta_ts =0 ; - ci.rta_tsage =0 ; -NLA_PUT (skb,RTA_CACHEINFO ,sizeof (ci), &ci); + + expires = rt->rt6i_expires ? rt->rt6i_expires - jiffies :0 ; +if (rtnl_put_cacheinfo (skb, &rt->u.dst,0 ,0 ,0 , + expires, rt->u.dst.error) <0 ) + goto nla_put_failure;return nlmsg_end (skb, nlh);
net/decnet/dn_route.c +5 -11
@@ -1469,7 +1469,7 @@struct rtmsg *r;struct nlmsghdr *nlh;unsigned char *b = skb->tail; -struct rta_cacheinfo ci; +long expires; nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (*r), flags); r =NLMSG_DATA (nlh);
@@ -1502,16 +1502,10 @@RTA_PUT (skb,RTA_GATEWAY ,2 , &rt->rt_gateway);if (rtnetlink_put_metrics (skb, rt->u.dst.metrics) <0 ) goto rtattr_failure; - ci.rta_lastuse =jiffies_to_clock_t (jiffies - rt->u.dst.lastuse); - ci.rta_used = rt->u.dst.__use; - ci.rta_clntref =atomic_read (&rt->u.dst.__refcnt); -if (rt->u.dst.expires) - ci.rta_expires =jiffies_to_clock_t (rt->u.dst.expires - jiffies); -else - ci.rta_expires =0 ; - ci.rta_error = rt->u.dst.error; - ci.rta_id = ci.rta_ts = ci.rta_tsage =0 ; -RTA_PUT (skb,RTA_CACHEINFO ,sizeof (ci), &ci); + expires = rt->u.dst.expires ? rt->u.dst.expires - jiffies :0 ; +if (rtnl_put_cacheinfo (skb, &rt->u.dst,0 ,0 ,0 , expires, + rt->u.dst.error) <0 ) + goto rtattr_failure;if (rt->fl.iif)RTA_PUT (skb,RTA_IIF ,sizeof (int ), &rt->fl.iif);
Resend: Need to export rtnl_put_cacheinfo() for IPv6
IPv4, IPv6, and DECNet all use struct rta_cacheinfo in a similiar way, therefore rtnl_put_cacheinfo() is added to reuse code.
Signed-off-by Thomas Graf <[email protected]>
net/core/rtnetlink.c +20 -0
@@ -212,6 +212,26 @@return nla_nest_cancel (skb, mx); } +int rtnl_put_cacheinfo (struct sk_buff *skb,struct dst_entry *dst,u32 id, +u32 ts,u32 tsage,long expires,u32 error) +{ +struct rta_cacheinfo ci = { + .rta_lastuse =jiffies_to_clock_t (jiffies - dst->lastuse), + .rta_used = dst->__use, + .rta_clntref =atomic_read (&(dst->__refcnt)), + .rta_error = error, + .rta_id = id, + .rta_ts = ts, + .rta_tsage = tsage, + }; + +if (expires) + ci.rta_expires =jiffies_to_clock_t (expires); + +return nla_put (skb,RTA_CACHEINFO ,sizeof (ci), &ci); +} + +EXPORT_SYMBOL_GPL (rtnl_put_cacheinfo);static void set_operstate (struct net_device *dev,unsigned char transition) {
include/linux/rtnetlink.h +3 -0
@@ -585,6 +585,9 @@ struct nlmsghdr *nlh, gfp_t flags);extern void rtnl_set_sk_err (u32 group,int error);extern int rtnetlink_put_metrics (struct sk_buff *skb,u32 *metrics); +extern int rtnl_put_cacheinfo (struct sk_buff *skb,struct dst_entry *dst, +u32 id,u32 ts,u32 tsage,long expires, +u32 error);extern void __rta_fill (struct sk_buff *skb,int attrtype,int attrlen,const void *data);
net/ipv4/route.c +11 -15
@@ -2629,7 +2629,8 @@struct rtable *rt = (struct rtable *)skb->dst;struct rtmsg *r;struct nlmsghdr *nlh; -struct rta_cacheinfo ci; +long expires; +u32 id =0 , ts =0 , tsage =0 , error; nlh =nlmsg_put (skb, pid, seq, event,sizeof (*r), flags);if (nlh ==NULL )
@@ -2676,20 +2677,13 @@if (rtnetlink_put_metrics (skb, rt->u.dst.metrics) <0 ) goto nla_put_failure; - ci.rta_lastuse =jiffies_to_clock_t (jiffies - rt->u.dst.lastuse); - ci.rta_used = rt->u.dst.__use; - ci.rta_clntref =atomic_read (&rt->u.dst.__refcnt); -if (rt->u.dst.expires) - ci.rta_expires =jiffies_to_clock_t (rt->u.dst.expires - jiffies); -else - ci.rta_expires =0 ; - ci.rta_error = rt->u.dst.error; - ci.rta_id = ci.rta_ts = ci.rta_tsage =0 ; + error = rt->u.dst.error; + expires = rt->u.dst.expires ? rt->u.dst.expires - jiffies :0 ;if (rt->peer) { - ci.rta_id = rt->peer->ip_id_count; + id = rt->peer->ip_id_count;if (rt->peer->tcp_ts_stamp) { - ci.rta_ts = rt->peer->tcp_ts; - ci.rta_tsage = xtime.tv_sec - rt->peer->tcp_ts_stamp; + ts = rt->peer->tcp_ts; + tsage = xtime.tv_sec - rt->peer->tcp_ts_stamp; } }
@@ -2708,7 +2702,7 @@ }else {if (err == -EMSGSIZE ) goto nla_put_failure; - ci.rta_error = err; + error = err; } } }else
@@ -2716,7 +2710,9 @@NLA_PUT_U32 (skb,RTA_IIF , rt->fl.iif); } -NLA_PUT (skb,RTA_CACHEINFO ,sizeof (ci), &ci); +if (rtnl_put_cacheinfo (skb, &rt->u.dst, id, ts, tsage, + expires, error) <0 ) + goto nla_put_failure;return nlmsg_end (skb, nlh);
net/ipv6/route.c +6 -13
@@ -2026,7 +2026,7 @@ {struct rtmsg *rtm;struct nlmsghdr *nlh; -struct rta_cacheinfo ci; +long expires;u32 table;if (prefix) {/* user wants prefix routes only */
@@ -2100,18 +2100,11 @@NLA_PUT_U32 (skb,RTA_OIF , rt->rt6i_dev->ifindex);NLA_PUT_U32 (skb,RTA_PRIORITY , rt->rt6i_metric); - ci.rta_lastuse =jiffies_to_clock_t (jiffies - rt->u.dst.lastuse); -if (rt->rt6i_expires) - ci.rta_expires =jiffies_to_clock_t (rt->rt6i_expires - jiffies); -else - ci.rta_expires =0 ; - ci.rta_used = rt->u.dst.__use; - ci.rta_clntref =atomic_read (&rt->u.dst.__refcnt); - ci.rta_error = rt->u.dst.error; - ci.rta_id =0 ; - ci.rta_ts =0 ; - ci.rta_tsage =0 ; -NLA_PUT (skb,RTA_CACHEINFO ,sizeof (ci), &ci); + + expires = rt->rt6i_expires ? rt->rt6i_expires - jiffies :0 ; +if (rtnl_put_cacheinfo (skb, &rt->u.dst,0 ,0 ,0 , + expires, rt->u.dst.error) <0 ) + goto nla_put_failure;return nlmsg_end (skb, nlh);
net/decnet/dn_route.c +5 -11
@@ -1469,7 +1469,7 @@struct rtmsg *r;struct nlmsghdr *nlh;unsigned char *b = skb->tail; -struct rta_cacheinfo ci; +long expires; nlh =NLMSG_NEW (skb, pid, seq, event,sizeof (*r), flags); r =NLMSG_DATA (nlh);
@@ -1502,16 +1502,10 @@RTA_PUT (skb,RTA_GATEWAY ,2 , &rt->rt_gateway);if (rtnetlink_put_metrics (skb, rt->u.dst.metrics) <0 ) goto rtattr_failure; - ci.rta_lastuse =jiffies_to_clock_t (jiffies - rt->u.dst.lastuse); - ci.rta_used = rt->u.dst.__use; - ci.rta_clntref =atomic_read (&rt->u.dst.__refcnt); -if (rt->u.dst.expires) - ci.rta_expires =jiffies_to_clock_t (rt->u.dst.expires - jiffies); -else - ci.rta_expires =0 ; - ci.rta_error = rt->u.dst.error; - ci.rta_id = ci.rta_ts = ci.rta_tsage =0 ; -RTA_PUT (skb,RTA_CACHEINFO ,sizeof (ci), &ci); + expires = rt->u.dst.expires ? rt->u.dst.expires - jiffies :0 ; +if (rtnl_put_cacheinfo (skb, &rt->u.dst,0 ,0 ,0 , expires, + rt->u.dst.error) <0 ) + goto rtattr_failure;if (rt->fl.iif)RTA_PUT (skb,RTA_IIF ,sizeof (int ), &rt->fl.iif);
David Miller
maintainerFrom: Thomas Graf <[email protected]>
Date: Mon, 27 Nov 2006 10:13:20 +0100
Quoted 6 lines
Resend: Need to export
rtnl_put_cacheinfo()for IPv6IPv4, IPv6, and DECNet all use struct
rta_cacheinfoin a similiar way, thereforertnl_put_cacheinfo()is added to reuse code.Signed-off-by Thomas Graf <[email protected]>
Also applied, thanks Thomas.