iproute2: Refactor: using new nl_msg struct for the all Netlink handlers
Subsystems (3)
PATCH v2 1/1 iproute2: Refactor: using new nl_msg struct for the all Netlink handlers
It will easy to extend with new parameters in future.
Signed-off-by Vadim Kochan <[email protected]>
--- bridge/br_common.h | 10 +++------ bridge/fdb.c | 5 +++-- bridge/link.c | 6 +++--- bridge/mdb.c | 5 +++-- bridge/monitor.c | 12 +++++------ bridge/vlan.c | 7 +++---- genl/ctrl.c | 10 +++++---- genl/genl.c | 5 ++--- genl/genl_utils.h | 2 +- include/libnetlink.h | 9 ++++++-- include/ll_map.h | 3 +-- ip/ip_common.h | 32 +++++++++-------------------- ip/ipaddress.c | 52 ++++++++++++++++++++++++---------------------- ip/ipaddrlabel.c | 8 +++++--- ip/ipl2tp.c | 8 ++++---- ip/iplink.c | 8 +++++--- ip/ipmonitor.c | 26 +++++++++++------------ ip/ipmroute.c | 5 +++-- ip/ipneigh.c | 5 +++-- ip/ipnetconf.c | 5 +++-- ip/ipntable.c | 5 +++-- ip/ipprefix.c | 5 +++-- ip/iproute.c | 28 ++++++++++++++++--------- ip/iprule.c | 8 +++++--- ip/iptoken.c | 3 ++- ip/rtmon.c | 6 +++--- ip/tcp_metrics.c | 10 +++++---- ip/xfrm.h | 6 ++---- ip/xfrm_monitor.c | 58 ++++++++++++++++++++++++++-------------------------- ip/xfrm_policy.c | 15 +++++++------- ip/xfrm_state.c | 19 +++++++++-------- lib/libnetlink.c | 16 ++++++++++++--- lib/ll_map.c | 4 ++-- misc/ifstat.c | 4 ++-- tc/m_action.c | 17 ++++++++------- tc/tc_class.c | 6 +++--- tc/tc_common.h | 8 ++++---- tc/tc_filter.c | 7 +++---- tc/tc_monitor.c | 14 ++++++------- tc/tc_qdisc.c | 7 +++---- 40 files changed, 248 insertions(+), 221 deletions(-)
bridge/br_common.h +3 -7
@@ -1,10 +1,6 @@ -extern int print_linkinfo (const struct sockaddr_nl *who, -struct nlmsghdr *n, -void *arg); -extern int print_fdb (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg); -extern int print_mdb (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg); +extern int print_linkinfo (struct nl_msg *msg,void *arg); +extern int print_fdb (struct nl_msg *msg,void *arg); +extern int print_mdb (struct nl_msg *msg,void *arg);extern int do_fdb (int argc,char **argv);extern int do_mdb (int argc,char **argv);
bridge/fdb.c +3 -2
@@ -58,9 +58,10 @@ static const char *state_n2a(unsigned s)return buf; } -int print_fdb (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +int print_fdb (struct nl_msg *msg,void *arg) { -FILE *fp = arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct ndmsg *r =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr * tb[NDA_MAX +1 ];
bridge/link.c +3 -3
@@ -96,10 +96,10 @@ static void print_hwmode(FILE *f, __u16 mode)fprintf (f,"hwmode %s " , hw_mode[mode]); } -int print_linkinfo (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg) +int print_linkinfo (struct nl_msg *msg,void *arg) { -FILE *fp = arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;int len = n->nlmsg_len;struct ifinfomsg *ifi =NLMSG_DATA (n);struct rtattr * tb[IFLA_MAX +1 ];
bridge/mdb.c +3 -2
@@ -77,9 +77,10 @@ static void br_print_mdb_entry(FILE *f, int ifindex, struct rtattr *attr) } } -int print_mdb (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +int print_mdb (struct nl_msg *msg,void *arg) { -FILE *fp = arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct br_port_msg *r =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr * tb[MDBA_MAX +1 ];
bridge/monitor.c +6 -6
@@ -46,10 +46,10 @@ static int show_mark(FILE *fp, const struct nlmsghdr *n)return 0 ; } -static int accept_msg (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg) +static int accept_msg (struct nl_msg *msg,void *arg) { -FILE *fp = arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;if (timestamp)print_timestamp (fp);
@@ -60,19 +60,19 @@ static int accept_msg(const struct sockaddr_nl *who,if (prefix_banner)fprintf (fp,"[LINK]" ); -return print_linkinfo (who, n, arg); +return print_linkinfo (msg, arg);case RTM_NEWNEIGH :case RTM_DELNEIGH :if (prefix_banner)fprintf (fp,"[NEIGH]" ); -return print_fdb (who, n, arg); +return print_fdb (msg, arg);case RTM_NEWMDB :case RTM_DELMDB :if (prefix_banner)fprintf (fp,"[MDB]" ); -return print_mdb (who, n, arg); +return print_mdb (msg, arg);case 15 :return show_mark (fp, n);
bridge/vlan.c +3 -4
@@ -101,11 +101,10 @@ static int vlan_modify(int cmd, int argc, char **argv)return 0 ; } -static int print_vlan (const struct sockaddr_nl *who, -struct nlmsghdr *n, -void *arg) +static int print_vlan (struct nl_msg *msg,void *arg) { -FILE *fp = arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct ifinfomsg *ifm =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr * tb[IFLA_MAX +1 ];
genl/ctrl.c +6 -4
@@ -177,14 +177,14 @@ static int print_ctrl_grp(FILE *fp, struct rtattr *arg, __u32 ctrl_ver)/* * The controller sends one nlmsg per family */ -static int print_ctrl (const struct sockaddr_nl *who,struct nlmsghdr *n, -void *arg) +static int print_ctrl (struct nl_msg *msg,void *arg) { +struct nlmsghdr *n = msg->n;struct rtattr *tb[CTRL_ATTR_MAX +1 ];struct genlmsghdr *ghdr =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr *attrs; -FILE *fp = (FILE *) arg; +FILE *fp = (FILE *)arg;__u32 ctrl_v =0x1 ;if (n->nlmsg_type !=GENL_ID_CTRL ) {
@@ -292,6 +292,7 @@ static int ctrl_list(int cmd, int argc, char **argv)struct nlmsghdr n;char buf[4096 ]; } req; +struct nl_msg msg = {};memset (&req,0 ,sizeof (req));
@@ -339,7 +340,8 @@ static int ctrl_list(int cmd, int argc, char **argv) goto ctrl_done; } -if (print_ctrl (NULL , nlh, (void *) stdout) <0 ) { + msg.n = nlh; +if (print_ctrl (&msg, (void *)stdout) <0 ) {fprintf (stderr,"Dump terminated\n" ); goto ctrl_done; }
genl/genl.c +2 -3
@@ -36,10 +36,9 @@ static void *BODY;static struct genl_util * genl_list; -static int print_nofopt (const struct sockaddr_nl *who,struct nlmsghdr *n, -void *arg) +static int print_nofopt (struct nl_msg *msg,void *arg) { -fprintf ((FILE *) arg,"unknown genl type ..\n" ); +fprintf ((FILE *)arg,"unknown genl type ..\n" );return 0 ; }
genl/genl_utils.h +1 -1
@@ -9,7 +9,7 @@ struct genl_utilstruct genl_util *next;char name[16 ];int (*parse_genlopt)(struct genl_util *fu,int argc,char **argv); -int (*print_genlopt)(const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg); +int (*print_genlopt)(struct nl_msg *msg,void *arg); };extern int genl_ctrl_resolve_family (const char *family);
include/libnetlink.h +7 -2
@@ -39,8 +39,13 @@ extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) __attribute__((warn_unused_result)); -typedef int (*rtnl_filter_t )(const struct sockaddr_nl *, -struct nlmsghdr *n,void *); +struct nl_msg +{ +struct sockaddr_nl *who; +struct nlmsghdr *n; +}; + +typedef int (*rtnl_filter_t )(struct nl_msg *msg,void *arg);struct rtnl_dump_filter_arg {
include/ll_map.h +1 -2
@@ -1,8 +1,7 @@#ifndef __LL_MAP_H__#define __LL_MAP_H__ 1 -extern int ll_remember_index (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg); +extern int ll_remember_index (struct nl_msg *msg,void *arg);extern void ll_init_map (struct rtnl_handle *rth);extern unsigned ll_name_to_index (const char *name);
ip/ip_common.h +10 -22
@@ -1,16 +1,9 @@extern int get_operstate (const char *name); -extern int print_linkinfo (const struct sockaddr_nl *who, -struct nlmsghdr *n, -void *arg); -extern int print_addrinfo (const struct sockaddr_nl *who, -struct nlmsghdr *n, -void *arg); -extern int print_addrlabel (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg); -extern int print_neigh (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg); -extern int print_ntable (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg); +extern int print_linkinfo (struct nl_msg *msg,void *arg); +extern int print_addrinfo (struct nl_msg *msg,void *arg); +extern int print_addrlabel (struct nl_msg *msg,void *arg); +extern int print_neigh (struct nl_msg *msg,void *arg); +extern int print_ntable (struct nl_msg *msg,void *arg);extern int ipaddr_list (int argc,char **argv);extern int ipaddr_list_link (int argc,char **argv);extern int iproute_monitor (int argc,char **argv);
@@ -21,16 +14,11 @@ void ipaddr_get_vf_rate(int, int *, int *, int);extern void ipaddr_reset_filter (int );extern void ipneigh_reset_filter (void );extern void ipntable_reset_filter (void ); -extern int print_route (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg); -extern int print_mroute (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg); -extern int print_prefix (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg); -extern int print_rule (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg); -extern int print_netconf (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg); +extern int print_route (struct nl_msg *msg,void *arg); +extern int print_mroute (struct nl_msg *msg,void *arg); +extern int print_prefix (struct nl_msg *msg,void *arg); +extern int print_rule (struct nl_msg *msg,void *arg); +extern int print_netconf (struct nl_msg *msg,void *arg);extern int do_ipaddr (int argc,char **argv);extern int do_ipaddrlabel (int argc,char **argv);extern int do_iproute (int argc,char **argv);
ip/ipaddress.c +27 -25
137 lines not on this page · raw message
ip/ipaddrlabel.c +5 -3
@@ -53,9 +53,10 @@ static void usage(void)exit (-1 ); } -int print_addrlabel (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +int print_addrlabel (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct ifaddrlblmsg *ifal =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr *tb[IFAL_MAX +1 ];
@@ -189,8 +190,9 @@ static int ipaddrlabel_modify(int cmd, int argc, char **argv) } -static int flush_addrlabel (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +static int flush_addrlabel (struct nl_msg *msg,void *arg) { +struct nlmsghdr *n = msg->n;struct rtnl_handle rth2;struct rtmsg *r =NLMSG_DATA (n);int len = n->nlmsg_len;
ip/ipl2tp.c +4 -4
@@ -354,9 +354,9 @@ static int get_response(struct nlmsghdr *n, void *arg)return 0 ; } -static int session_nlmsg (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +static int session_nlmsg (struct nl_msg *msg,void *arg) { -int ret =get_response (n, arg); +int ret =get_response (msg->n, arg);if (ret ==0 )print_session (arg);
@@ -388,9 +388,9 @@ static int get_session(struct l2tp_data *p)return 0 ; } -static int tunnel_nlmsg (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +static int tunnel_nlmsg (struct nl_msg *msg,void *arg) { -int ret =get_response (n, arg); +int ret =get_response (msg->n, arg);if (ret ==0 )print_tunnel (arg);
ip/iplink.c +5 -3
@@ -174,9 +174,9 @@ static int get_addr_gen_mode(const char *mode)#if IPLINK_IOCTL_COMPAT static int have_rtnl_newlink =-1 ; -static int accept_msg (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg) +static int accept_msg (struct nl_msg *msg,void *arg) { +struct nlmsghdr *n = msg->n;struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA (n); if (n->nlmsg_type == NLMSG_ERROR &&
@@ -734,6 +734,7 @@ int iplink_get(unsigned int flags, char *name, __u32 filt_mask)int len;struct iplink_req req;char answer[16384 ]; +struct nl_msg msg = {};memset (&req,0 ,sizeof (req));
@@ -756,7 +757,8 @@ int iplink_get(unsigned int flags, char *name, __u32 filt_mask)if (rtnl_talk (&rth, &req.n,0 ,0 , (struct nlmsghdr *)answer) <0 )return -2 ; -print_linkinfo (NULL , (struct nlmsghdr *)answer, stdout); + msg.n = (struct nlmsghdr *)answer; +print_linkinfo (&msg, (void *)stdout);return 0 ; }
ip/ipmonitor.c +13 -13
@@ -36,10 +36,10 @@ static void usage(void)exit (-1 ); } -static int accept_msg (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg) +static int accept_msg (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;if (timestamp)print_timestamp (fp);
@@ -57,32 +57,32 @@ static int accept_msg(const struct sockaddr_nl *who, r->rtm_family == RTNL_FAMILY_IP6MR) { if (prefix_banner) fprintf(fp, "[MROUTE]"); - print_mroute(who, n, arg); + print_mroute(msg, arg); return 0; } else {if (prefix_banner)fprintf (fp,"[ROUTE]" ); -print_route (who, n, arg); +print_route (msg, arg);return 0 ; } }if (n->nlmsg_type ==RTM_NEWLINK || n->nlmsg_type ==RTM_DELLINK ) { -ll_remember_index (who, n,NULL ); +ll_remember_index (msg, arg);if (prefix_banner)fprintf (fp,"[LINK]" ); -print_linkinfo (who, n, arg); +print_linkinfo (msg, arg);return 0 ; }if (n->nlmsg_type ==RTM_NEWADDR || n->nlmsg_type ==RTM_DELADDR ) {if (prefix_banner)fprintf (fp,"[ADDR]" ); -print_addrinfo (who, n, arg); +print_addrinfo (msg, arg);return 0 ; }if (n->nlmsg_type ==RTM_NEWADDRLABEL || n->nlmsg_type ==RTM_DELADDRLABEL ) {if (prefix_banner)fprintf (fp,"[ADDRLABEL]" ); -print_addrlabel (who, n, arg); +print_addrlabel (msg, arg);return 0 ; } if (n->nlmsg_type == RTM_NEWNEIGH || n->nlmsg_type == RTM_DELNEIGH ||
@@ -96,25 +96,25 @@ static int accept_msg(const struct sockaddr_nl *who,if (prefix_banner)fprintf (fp,"[NEIGH]" ); -print_neigh (who, n, arg); +print_neigh (msg, arg);return 0 ; }if (n->nlmsg_type ==RTM_NEWPREFIX ) {if (prefix_banner)fprintf (fp,"[PREFIX]" ); -print_prefix (who, n, arg); +print_prefix (msg, arg);return 0 ; }if (n->nlmsg_type ==RTM_NEWRULE || n->nlmsg_type ==RTM_DELRULE ) {if (prefix_banner)fprintf (fp,"[RULE]" ); -print_rule (who, n, arg); +print_rule (msg, arg);return 0 ; }if (n->nlmsg_type ==RTM_NEWNETCONF ) {if (prefix_banner)fprintf (fp,"[NETCONF]" ); -print_netconf (who, n, arg); +print_netconf (msg, arg);return 0 ; }if (n->nlmsg_type ==15 ) {
ip/ipmroute.c +3 -2
@@ -53,9 +53,10 @@ struct rtfilterinet_prefix msrc; } filter; -int print_mroute (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +int print_mroute (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct rtmsg *r =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr * tb[RTA_MAX +1 ];
ip/ipneigh.c +3 -2
@@ -181,9 +181,10 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv) } -int print_neigh (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +int print_neigh (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct ndmsg *r =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr * tb[NDA_MAX +1 ];
ip/ipnetconf.c +3 -2
@@ -40,9 +40,10 @@ static void usage(void)#define NETCONF_RTA (r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct netconfmsg)))) -int print_netconf (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +int print_netconf (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct netconfmsg *ncm =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr *tb[NETCONFA_MAX +1 ];
ip/ipntable.c +3 -2
@@ -349,9 +349,10 @@ static const char *ntable_strtime_delta(__u32 msec)return str; } -int print_ntable (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +int print_ntable (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct ndtmsg *ndtm =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr *tb[NDTA_MAX +1 ];
ip/ipprefix.c +3 -2
@@ -35,9 +35,10 @@#define IF_PREFIX_ONLINK 0x01#define IF_PREFIX_AUTOCONF 0x02 -int print_prefix (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +int print_prefix (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct prefixmsg *prefix =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr * tb[RTA_MAX +1 ];
ip/iproute.c +18 -10
@@ -280,9 +280,10 @@ static int calc_host_len(const struct rtmsg *r)return -1 ; } -int print_route (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +int print_route (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct rtmsg *r =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr * tb[RTA_MAX +1 ];
@@ -1078,9 +1079,9 @@ static int iproute_flush_cache(void)static __u32 route_dump_magic =0x45311224 ; -static int save_route (const struct sockaddr_nl *who,struct nlmsghdr *n, -void *arg) +static int save_route (struct nl_msg *msg,void *arg) { +struct nlmsghdr *n = msg->n;int ret;int len = n->nlmsg_len;struct rtmsg *r =NLMSG_DATA (n);
@@ -1382,6 +1383,7 @@ static int iproute_get(int argc, char **argv)int connected =0 ;int from_ok =0 ;unsigned int mark =0 ; +struct nl_msg msg = {};memset (&req,0 ,sizeof (req));
@@ -1483,12 +1485,13 @@ static int iproute_get(int argc, char **argv)if (rtnl_talk (&rth, &req.n,0 ,0 , &req.n) <0 )exit (2 ); + msg.n = &req.n;if (connected && !from_ok) {struct rtmsg *r =NLMSG_DATA (&req.n);int len = req.n.nlmsg_len;struct rtattr * tb[RTA_MAX +1 ]; -if (print_route (NULL , &req.n, (void *)stdout) <0 ) { +if (print_route (&msg, (void *)stdout) <0 ) {fprintf (stderr,"An error :-)\n" );exit (1 ); }
@@ -1525,7 +1528,7 @@ static int iproute_get(int argc, char **argv)exit (2 ); } -if (print_route (NULL , &req.n, (void *)stdout) <0 ) { +if (print_route (&msg, (void *)stdout) <0 ) {fprintf (stderr,"An error :-)\n" );exit (1 ); }
@@ -1533,9 +1536,9 @@ static int iproute_get(int argc, char **argv)exit (0 ); } -static int restore_handler (const struct sockaddr_nl *nl,struct nlmsghdr *n, -void *arg) +static int restore_handler (struct nl_msg *msg,void *arg) { +struct nlmsghdr *n = msg->n;int ret; n->nlmsg_flags |=NLM_F_REQUEST |NLM_F_CREATE |NLM_F_ACK ;
@@ -1576,9 +1579,14 @@ static int iproute_restore(void)exit (rtnl_from_file (stdin, &restore_handler,NULL )); } -static int show_handler (const struct sockaddr_nl *nl,struct nlmsghdr *n,void *arg) +static int show_handler (struct nl_msg *msg,void *arg) { -print_route (nl, n, stdout); +struct nl_msg rt_param = {}; + + rt_param.n = msg->n; + rt_param.who = msg->who; + +print_route (&rt_param, (void *)stdout);return 0 ; }
ip/iprule.c +5 -3
@@ -46,9 +46,10 @@ static void usage(void)exit (-1 ); } -int print_rule (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +int print_rule (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct rtmsg *r =NLMSG_DATA (n);int len = n->nlmsg_len;int host_len =-1 ;
@@ -392,8 +393,9 @@ static int iprule_modify(int cmd, int argc, char **argv) } -static int flush_rule (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +static int flush_rule (struct nl_msg *msg,void *arg) { +struct nlmsghdr *n = msg->n;struct rtnl_handle rth2;struct rtmsg *r =NLMSG_DATA (n);int len = n->nlmsg_len;
ip/iptoken.c +2 -1
@@ -42,8 +42,9 @@ static void usage(void)exit (-1 ); } -static int print_token (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) +static int print_token (struct nl_msg *msg,void *arg) { +struct nlmsghdr *n = msg->n;struct rtnl_dump_args *args = arg;FILE *fp = args->fp;int ifindex = args->ifindex;
ip/rtmon.c +3 -3
@@ -45,10 +45,10 @@ static void write_stamp(FILE *fp)fwrite ((void *)n1,1 ,NLMSG_ALIGN (n1->nlmsg_len), fp); } -static int dump_msg (const struct sockaddr_nl *who,struct nlmsghdr *n, -void *arg) +static int dump_msg (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;if (!init_phase)write_stamp (fp);fwrite ((void *)n,1 ,NLMSG_ALIGN (n->nlmsg_len), fp);
ip/tcp_metrics.c +6 -4
@@ -88,10 +88,10 @@ static int flush_update(void)return 0 ; } -static int process_msg (const struct sockaddr_nl *who,struct nlmsghdr *n, -void *arg) +static int process_msg (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *) arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct genlmsghdr *ghdr;struct rtattr *attrs[TCP_METRICS_ATTR_MAX +1 ], *a;int len = n->nlmsg_len;
@@ -295,6 +295,7 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv)TCPM_REQUEST (req,1024 ,TCP_METRICS_CMD_GET ,NLM_F_REQUEST );int atype =-1 , stype =-1 ;int ack; +struct nl_msg msg = {};memset (&f,0 ,sizeof (f)); f.daddr.bitlen =-1 ;
@@ -455,7 +456,8 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv) }else if (atype >=0 ) {if (rtnl_talk (&grth, &req.n,0 ,0 , &req.n) <0 )return -2 ; -if (process_msg (NULL , &req.n, stdout) <0 ) { + msg.n = &req.n; +if (process_msg (&msg, (void *)stdout) <0 ) {fprintf (stderr,"Dump terminated\n" );exit (1 ); }
ip/xfrm.h +2 -4
@@ -107,10 +107,8 @@ struct xfrm_filter {extern struct xfrm_filter filter; -int xfrm_state_print (const struct sockaddr_nl *who,struct nlmsghdr *n, -void *arg); -int xfrm_policy_print (const struct sockaddr_nl *who,struct nlmsghdr *n, -void *arg); +int xfrm_state_print (struct nl_msg *msg,void *arg); +int xfrm_policy_print (struct nl_msg *msg,void *arg);int do_xfrm_state (int argc,char **argv);int do_xfrm_policy (int argc,char **argv);int do_xfrm_monitor (int argc,char **argv);
ip/xfrm_monitor.c +29 -29
131 lines not on this page · raw message
ip/xfrm_policy.c +8 -7
@@ -456,16 +456,16 @@ static int xfrm_policy_filter_match(struct xfrm_userpolicy_info *xpinfo,return 1 ; } -int xfrm_policy_print (const struct sockaddr_nl *who,struct nlmsghdr *n, -void *arg) +int xfrm_policy_print (struct nl_msg *msg,void *arg) { +struct nlmsghdr *n = msg->n;struct rtattr * tb[XFRMA_MAX +1 ];struct rtattr * rta;struct xfrm_userpolicy_info *xpinfo =NULL ;struct xfrm_user_polexpire *xpexp =NULL ;struct xfrm_userpolicy_id *xpid =NULL ;__u8 ptype =XFRM_POLICY_TYPE_MAIN ; -FILE *fp = (FILE *)arg; +FILE *fp = (FILE *)arg;int len = n->nlmsg_len; if (n->nlmsg_type != XFRM_MSG_NEWPOLICY &&
@@ -686,12 +686,14 @@ static int xfrm_policy_get(int argc, char **argv) {char buf[NLMSG_BUF_SIZE ];struct nlmsghdr *n = (struct nlmsghdr *)buf; +struct nl_msg msg = {};memset (buf,0 ,sizeof (buf));xfrm_policy_get_or_delete (argc, argv,0 , n); -if (xfrm_policy_print (NULL , n, (void *)stdout) <0 ) { + msg.n = n; +if (xfrm_policy_print (&msg, (void *)stdout) <0 ) {fprintf (stderr,"An error :-)\n" );exit (1 ); }
@@ -703,10 +705,9 @@ static int xfrm_policy_get(int argc, char **argv)* With an existing policy of nlmsg, make new nlmsg for deleting the policy * and store it to buffer. */ -static int xfrm_policy_keep (const struct sockaddr_nl *who, -struct nlmsghdr *n, -void *arg) +static int xfrm_policy_keep (struct nl_msg *msg,void *arg) { +struct nlmsghdr *n = msg->n;struct xfrm_buffer *xb = (struct xfrm_buffer *)arg;struct rtnl_handle *rth = xb->rth;struct xfrm_userpolicy_info *xpinfo =NLMSG_DATA (n);
ip/xfrm_state.c +11 -8
@@ -665,6 +665,7 @@ static int xfrm_state_allocspi(int argc, char **argv)struct xfrm_mark mark = {0 ,0 };char res_buf[NLMSG_BUF_SIZE ];struct nlmsghdr *res_n = (struct nlmsghdr *)res_buf; +struct nl_msg msg = {};memset (res_buf,0 ,sizeof (res_buf));
@@ -783,7 +784,8 @@ static int xfrm_state_allocspi(int argc, char **argv)if (rtnl_talk (&rth, &req.n,0 ,0 , res_n) <0 )exit (2 ); -if (xfrm_state_print (NULL , res_n, (void *)stdout) <0 ) { + msg.n = res_n; +if (xfrm_state_print (&msg, (void *)stdout) <0 ) {fprintf (stderr,"An error :-)\n" );exit (1 ); }
@@ -821,10 +823,10 @@ static int xfrm_state_filter_match(struct xfrm_usersa_info *xsinfo)return 1 ; } -int xfrm_state_print (const struct sockaddr_nl *who,struct nlmsghdr *n, -void *arg) +int xfrm_state_print (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct rtattr * tb[XFRMA_MAX +1 ];struct rtattr * rta;struct xfrm_usersa_info *xsinfo =NULL ;
@@ -975,13 +977,15 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete) }else {char buf[NLMSG_BUF_SIZE ];struct nlmsghdr *res_n = (struct nlmsghdr *)buf; +struct nl_msg msg = {};memset (buf,0 ,sizeof (buf));if (rtnl_talk (&rth, &req.n,0 ,0 , res_n) <0 )exit (2 ); -if (xfrm_state_print (NULL , res_n, (void *)stdout) <0 ) { + msg.n = res_n; +if (xfrm_state_print (&msg, (void *)stdout) <0 ) {fprintf (stderr,"An error :-)\n" );exit (1 ); }
@@ -996,10 +1000,9 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete)* With an existing state of nlmsg, make new nlmsg for deleting the state * and store it to buffer. */ -static int xfrm_state_keep (const struct sockaddr_nl *who, -struct nlmsghdr *n, -void *arg) +static int xfrm_state_keep (struct nl_msg *msg,void *arg) { +struct nlmsghdr *n = msg->n;struct xfrm_buffer *xb = (struct xfrm_buffer *)arg;struct rtnl_handle *rth = xb->rth;struct xfrm_usersa_info *xsinfo =NLMSG_DATA (n);
lib/libnetlink.c +13 -3
@@ -220,6 +220,7 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth, }for (a = arg; a->filter; a++) { +struct nl_msg msg = {};struct nlmsghdr *h = (struct nlmsghdr *)buf; msglen = status;
@@ -249,7 +250,10 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth, }return -1 ; } - err = a->filter (&nladdr, h, a->arg1); + + msg.who = &nladdr; + msg.n = h; + err = a->filter (&msg, a->arg1);if (err <0 )return err;
@@ -450,6 +454,7 @@ int rtnl_listen(struct rtnl_handle *rtnl,exit (1 ); }for (h = (struct nlmsghdr *)buf; status >=sizeof (*h); ) { +struct nl_msg m = {};int err;int len = h->nlmsg_len;int l = len -sizeof (*h);
@@ -463,7 +468,9 @@ int rtnl_listen(struct rtnl_handle *rtnl,exit (1 ); } - err =handler (&nladdr, h, jarg); + m.who = &nladdr; + m.n = h; + err =handler (&m, jarg);if (err <0 )return err;
@@ -495,6 +502,7 @@ int rtnl_from_file(FILE *rtnl, rtnl_filter_t handler, nladdr.nl_groups =0 ;while (1 ) { +struct nl_msg msg = {};int err, len;int l;
@@ -529,7 +537,9 @@ int rtnl_from_file(FILE *rtnl, rtnl_filter_t handler,return -1 ; } - err =handler (&nladdr, h, jarg); + msg.who = &nladdr; + msg.n = h; + err =handler (&msg, jarg);if (err <0 )return err; }
lib/ll_map.c +2 -2
@@ -78,9 +78,9 @@ static struct ll_cache *ll_get_by_name(const char *name)return NULL ; } -int ll_remember_index (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg) +int ll_remember_index (struct nl_msg *msg,void *arg) { +struct nlmsghdr *n = msg->n;unsigned int h;const char *ifname;struct ifinfomsg *ifi =NLMSG_DATA (n);
misc/ifstat.c +2 -2
@@ -105,9 +105,9 @@ static int match(const char *id)return 0 ; } -static int get_nlmsg (const struct sockaddr_nl *who, -struct nlmsghdr *m,void *arg) +static int get_nlmsg (struct nl_msg *msg,void *arg) { +struct nlmsghdr *m = msg->n;struct ifinfomsg *ifi =NLMSG_DATA (m);struct rtattr * tb[IFLA_MAX +1 ];int len = m->nlmsg_len;
tc/m_action.c +10 -7
@@ -319,11 +319,10 @@ tc_print_action(FILE * f, const struct rtattr *arg)return 0 ; } -int print_action (const struct sockaddr_nl *who, -struct nlmsghdr *n, -void *arg) +int print_action (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct tcamsg *t =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr * tb[TCAA_MAX +1 ];
@@ -460,9 +459,13 @@ static int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p)return 1 ; } -if (ans &&print_action (NULL , &req.n, (void *)stdout) <0 ) { -fprintf (stderr,"Dump terminated\n" ); -return 1 ; +if (ans) { +struct nl_msg msg = {}; + msg.n = &req.n; +if (print_action (&msg, (void *)stdout) <0 ) { +fprintf (stderr,"Dump terminated\n" ); +return 1 ; + } } *argc_p = argc;
tc/tc_class.c +3 -3
@@ -148,10 +148,10 @@ int filter_ifindex;__u32 filter_qdisc;__u32 filter_classid; -int print_class (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg) +int print_class (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct tcmsg *t =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr * tb[TCA_MAX +1 ];
tc/tc_common.h +4 -4
@@ -7,10 +7,10 @@ extern int do_class(int argc, char **argv);extern int do_filter (int argc,char **argv);extern int do_action (int argc,char **argv);extern int do_tcmonitor (int argc,char **argv); -extern int print_action (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg); -extern int print_filter (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg); -extern int print_qdisc (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg); -extern int print_class (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg); +extern int print_action (struct nl_msg *msg,void *arg); +extern int print_filter (struct nl_msg *msg,void *arg); +extern int print_qdisc (struct nl_msg *msg,void *arg); +extern int print_class (struct nl_msg *msg,void *arg);extern void print_size_table (FILE *fp,const char *prefix,struct rtattr *rta);struct tc_estimator ;
tc/tc_filter.c +3 -4
@@ -181,11 +181,10 @@ static __u32 filter_prio;static __u32 filter_protocol;__u16 f_proto =0 ; -int print_filter (const struct sockaddr_nl *who, -struct nlmsghdr *n, -void *arg) +int print_filter (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct tcmsg *t =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr * tb[TCA_MAX +1 ];
tc/tc_monitor.c +7 -7
@@ -35,26 +35,26 @@ static void usage(void) } -static int accept_tcmsg (const struct sockaddr_nl *who, -struct nlmsghdr *n,void *arg) +static int accept_tcmsg (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;if (n->nlmsg_type ==RTM_NEWTFILTER || n->nlmsg_type ==RTM_DELTFILTER ) { -print_filter (who, n, arg); +print_filter (msg, arg);return 0 ; }if (n->nlmsg_type ==RTM_NEWTCLASS || n->nlmsg_type ==RTM_DELTCLASS ) { -print_class (who, n, arg); +print_class (msg, arg);return 0 ; }if (n->nlmsg_type ==RTM_NEWQDISC || n->nlmsg_type ==RTM_DELQDISC ) { -print_qdisc (who, n, arg); +print_qdisc (msg, arg);return 0 ; }if (n->nlmsg_type ==RTM_GETACTION || n->nlmsg_type ==RTM_NEWACTION || n->nlmsg_type ==RTM_DELACTION ) { -print_action (who, n, arg); +print_action (msg, arg);return 0 ; } if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
tc/tc_qdisc.c +3 -4
@@ -195,11 +195,10 @@ static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)static int filter_ifindex; -int print_qdisc (const struct sockaddr_nl *who, -struct nlmsghdr *n, -void *arg) +int print_qdisc (struct nl_msg *msg,void *arg) { -FILE *fp = (FILE *)arg; +struct nlmsghdr *n = msg->n; +FILE *fp = (FILE *)arg;struct tcmsg *t =NLMSG_DATA (n);int len = n->nlmsg_len;struct rtattr * tb[TCA_MAX +1 ];
Signature · 1 line
2.1.0
Quoted 3 lines · On Fri, 5 Sep 2014 13:35:28 +0300 Vadim Kochan <[email protected]> wrote:
It will easy to extend with new parameters in future.
Signed-off-by Vadim Kochan <[email protected]>
This is a big change and not needed yet. Please hold off refactoring until the new parameters are actually needed.