From 00a337473eb0fe5140bfe04d97f07d72352e2ffc Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Sat, 28 Jan 2012 02:50:39 +0300 Subject: [PATCH] zdtm: cleanout netlink00 Signed-off-by: Andrey Vagin --- test/zdtm/live/streaming/netlink00.c | 120 +++++++++++---------------- 1 file changed, 48 insertions(+), 72 deletions(-) diff --git a/test/zdtm/live/streaming/netlink00.c b/test/zdtm/live/streaming/netlink00.c index fa011530b..d27d4307e 100644 --- a/test/zdtm/live/streaming/netlink00.c +++ b/test/zdtm/live/streaming/netlink00.c @@ -94,25 +94,19 @@ int main(int argc, char *argv[]) test_daemon(); while (test_go()){ - for (i=0;irta_type) { @@ -255,75 +247,59 @@ int read_reply() return 0; } -int form_request_add() -{ - // attributes of the route entry - int ifcn = 1; //interface number - // initialize RTNETLINK request buffer - bzero(&req, sizeof(req)); - // compute the initial length of the - // service request - rtl = sizeof(struct rtmsg); - // add first attrib: - // set destination IP addr and increment the - // RTNETLINK buffer size - rtap = (struct rtattr *) req.buf; - rtap->rta_type = RTA_DST; - rtap->rta_len = sizeof(struct rtattr) + 4; - inet_pton(AF_INET, dsts, - ((char *)rtap) + sizeof(struct rtattr)); - rtl += rtap->rta_len; - // add second attrib: - // set ifc index and increment the size - rtap = (struct rtattr *) (((char *)rtap) - + rtap->rta_len); - rtap->rta_type = RTA_OIF;//Output interface index - rtap->rta_len = sizeof(struct rtattr) + 4; - memcpy(((char *)rtap) + sizeof(struct rtattr), - &ifcn, sizeof(int)); - rtl += rtap->rta_len; - // setup the NETLINK header - req.nl.nlmsg_len = NLMSG_LENGTH(rtl); - req.nl.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK; - req.nl.nlmsg_type = RTM_NEWROUTE; - // setup the service header (struct rtmsg) - req.rt.rtm_family = AF_INET; - req.rt.rtm_table = RT_TABLE_MAIN; - req.rt.rtm_protocol = RTPROT_STATIC; - req.rt.rtm_scope = RT_SCOPE_UNIVERSE; - req.rt.rtm_type = RTN_UNICAST; - // set the network prefix size - req.rt.rtm_dst_len = pn; - return 0; -} +#define NLMSG_TAIL(nmsg) \ + ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) + int form_request_del() { - // attributes of the route entry - // initialize RTNETLINK request buffer bzero(&req, sizeof(req)); - // compute the initial length of the - // service request - rtl = sizeof(struct rtmsg); - // add first attrib: - // set destination IP addr and increment the - // RTNETLINK buffer size - rtap = (struct rtattr *) req.buf; + req.nl.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); + + rtap = NLMSG_TAIL(&req.nl); rtap->rta_type = RTA_DST; - rtap->rta_len = sizeof(struct rtattr) + 4; + rtap->rta_len = RTA_LENGTH(4); inet_pton(AF_INET, dsts, ((char *)rtap) + sizeof(struct rtattr)); - rtl += rtap->rta_len; - // setup the NETLINK header - req.nl.nlmsg_len = NLMSG_LENGTH(rtl); - req.nl.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK; + req.nl.nlmsg_len = NLMSG_ALIGN(req.nl.nlmsg_len) + RTA_ALIGN(rtap->rta_len); + req.nl.nlmsg_flags = NLM_F_CREATE | NLM_F_ACK | NLM_F_REQUEST; req.nl.nlmsg_type = RTM_DELROUTE; - // setup the service header (struct rtmsg) req.rt.rtm_family = AF_INET; req.rt.rtm_table = RT_TABLE_MAIN; req.rt.rtm_protocol = RTPROT_STATIC; req.rt.rtm_scope = RT_SCOPE_UNIVERSE; req.rt.rtm_type = RTN_UNICAST; - // set the network prefix size + req.rt.rtm_dst_len = pn; + return 0; +} + +int form_request_add() +{ + int ifcn = 1; //interface number + + bzero(&req, sizeof(req)); + req.nl.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); + rtap = NLMSG_TAIL(&req.nl); + rtap->rta_type = RTA_DST; + rtap->rta_len = RTA_LENGTH(4); + inet_pton(AF_INET, dsts, + ((char *)rtap) + sizeof(struct rtattr)); + req.nl.nlmsg_len = NLMSG_ALIGN(req.nl.nlmsg_len) + RTA_ALIGN(rtap->rta_len); + + rtap = NLMSG_TAIL(&req.nl);; + rtap->rta_type = RTA_OIF;//Output interface index + rtap->rta_len = RTA_LENGTH(sizeof(int)); + memcpy(((char *)rtap) + sizeof(struct rtattr), + &ifcn, sizeof(int)); + + req.nl.nlmsg_len = NLMSG_ALIGN(req.nl.nlmsg_len) + RTA_ALIGN(rtap->rta_len); + req.nl.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK; + req.nl.nlmsg_type = RTM_NEWROUTE; + + req.rt.rtm_family = AF_INET; + req.rt.rtm_table = RT_TABLE_MAIN; + req.rt.rtm_protocol = RTPROT_STATIC; + req.rt.rtm_scope = RT_SCOPE_UNIVERSE; + req.rt.rtm_type = RTN_UNICAST; req.rt.rtm_dst_len = pn; return 0; }