aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute/libnetlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/libiproute/libnetlink.c')
-rw-r--r--networking/libiproute/libnetlink.c66
1 files changed, 34 insertions, 32 deletions
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c
index cbb5daf95..7e0ff1b6c 100644
--- a/networking/libiproute/libnetlink.c
+++ b/networking/libiproute/libnetlink.c
@@ -68,30 +68,32 @@ int FAST_FUNC rtnl_send(struct rtnl_handle *rth, char *buf, int len)
68 68
69int FAST_FUNC rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) 69int FAST_FUNC rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
70{ 70{
71 struct nlmsghdr nlh; 71 struct {
72 struct sockaddr_nl nladdr; 72 struct nlmsghdr nlh;
73 struct iovec iov[2] = { { &nlh, sizeof(nlh) }, { req, len } }; 73 struct msghdr msg;
74 /* Use designated initializers, struct layout is non-portable */ 74 struct sockaddr_nl nladdr;
75 struct msghdr msg = { 75 } s;
76 .msg_name = (void*)&nladdr, 76 struct iovec iov[2] = { { &s.nlh, sizeof(s.nlh) }, { req, len } };
77 .msg_namelen = sizeof(nladdr), 77
78 .msg_iov = iov, 78 memset(&s, 0, sizeof(s));
79 .msg_iovlen = 2, 79
80 .msg_control = NULL, 80 s.msg.msg_name = (void*)&s.nladdr;
81 .msg_controllen = 0, 81 s.msg.msg_namelen = sizeof(s.nladdr);
82 .msg_flags = 0 82 s.msg.msg_iov = iov;
83 }; 83 s.msg.msg_iovlen = 2;
84 84 /*s.msg.msg_control = NULL; - already is */
85 memset(&nladdr, 0, sizeof(nladdr)); 85 /*s.msg.msg_controllen = 0; - already is */
86 nladdr.nl_family = AF_NETLINK; 86 /*s.msg.msg_flags = 0; - already is */
87 87
88 nlh.nlmsg_len = NLMSG_LENGTH(len); 88 s.nladdr.nl_family = AF_NETLINK;
89 nlh.nlmsg_type = type; 89
90 nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST; 90 s.nlh.nlmsg_len = NLMSG_LENGTH(len);
91 nlh.nlmsg_pid = 0; 91 s.nlh.nlmsg_type = type;
92 nlh.nlmsg_seq = rth->dump = ++rth->seq; 92 s.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
93 93 /*s.nlh.nlmsg_pid = 0; - already is */
94 return sendmsg(rth->fd, &msg, 0); 94 s.nlh.nlmsg_seq = rth->dump = ++rth->seq;
95
96 return sendmsg(rth->fd, &s.msg, 0);
95} 97}
96 98
97static int rtnl_dump_filter(struct rtnl_handle *rth, 99static int rtnl_dump_filter(struct rtnl_handle *rth,
@@ -338,14 +340,14 @@ int FAST_FUNC addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data)
338 int len = RTA_LENGTH(4); 340 int len = RTA_LENGTH(4);
339 struct rtattr *rta; 341 struct rtattr *rta;
340 342
341 if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) { 343 if ((int)(NLMSG_ALIGN(n->nlmsg_len + len)) > maxlen) {
342 return -1; 344 return -1;
343 } 345 }
344 rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); 346 rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len));
345 rta->rta_type = type; 347 rta->rta_type = type;
346 rta->rta_len = len; 348 rta->rta_len = len;
347 move_to_unaligned32(RTA_DATA(rta), data); 349 move_to_unaligned32(RTA_DATA(rta), data);
348 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len; 350 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len + len);
349 return 0; 351 return 0;
350} 352}
351 353
@@ -354,14 +356,14 @@ int FAST_FUNC addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, in
354 int len = RTA_LENGTH(alen); 356 int len = RTA_LENGTH(alen);
355 struct rtattr *rta; 357 struct rtattr *rta;
356 358
357 if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) { 359 if ((int)(NLMSG_ALIGN(n->nlmsg_len + len)) > maxlen) {
358 return -1; 360 return -1;
359 } 361 }
360 rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); 362 rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len));
361 rta->rta_type = type; 363 rta->rta_type = type;
362 rta->rta_len = len; 364 rta->rta_len = len;
363 memcpy(RTA_DATA(rta), data, alen); 365 memcpy(RTA_DATA(rta), data, alen);
364 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len; 366 n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len + len);
365 return 0; 367 return 0;
366} 368}
367 369
@@ -370,14 +372,14 @@ int FAST_FUNC rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t d
370 int len = RTA_LENGTH(4); 372 int len = RTA_LENGTH(4);
371 struct rtattr *subrta; 373 struct rtattr *subrta;
372 374
373 if (RTA_ALIGN(rta->rta_len) + len > maxlen) { 375 if (RTA_ALIGN(rta->rta_len + len) > maxlen) {
374 return -1; 376 return -1;
375 } 377 }
376 subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len)); 378 subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
377 subrta->rta_type = type; 379 subrta->rta_type = type;
378 subrta->rta_len = len; 380 subrta->rta_len = len;
379 move_to_unaligned32(RTA_DATA(subrta), data); 381 move_to_unaligned32(RTA_DATA(subrta), data);
380 rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len; 382 rta->rta_len = NLMSG_ALIGN(rta->rta_len + len);
381 return 0; 383 return 0;
382} 384}
383 385
@@ -386,14 +388,14 @@ int FAST_FUNC rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data
386 struct rtattr *subrta; 388 struct rtattr *subrta;
387 int len = RTA_LENGTH(alen); 389 int len = RTA_LENGTH(alen);
388 390
389 if (RTA_ALIGN(rta->rta_len) + len > maxlen) { 391 if (RTA_ALIGN(rta->rta_len + len) > maxlen) {
390 return -1; 392 return -1;
391 } 393 }
392 subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len)); 394 subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
393 subrta->rta_type = type; 395 subrta->rta_type = type;
394 subrta->rta_len = len; 396 subrta->rta_len = len;
395 memcpy(RTA_DATA(subrta), data, alen); 397 memcpy(RTA_DATA(subrta), data, alen);
396 rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len; 398 rta->rta_len = NLMSG_ALIGN(rta->rta_len + len);
397 return 0; 399 return 0;
398} 400}
399 401