Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/networking/libiproute/libnetlink.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/networking/libiproute/libnetlink.c
r821 r1770 1 /* vi: set sw=4 ts=4: */ 1 2 /* 2 3 * libnetlink.c RTnetlink service routines. … … 11 12 */ 12 13 14 #include <sys/socket.h> 15 #include <sys/uio.h> 16 13 17 #include "libbb.h" 14 #include <sys/socket.h>15 16 #include <errno.h>17 #include <string.h>18 #include <time.h>19 #include <unistd.h>20 21 #include <sys/uio.h>22 23 18 #include "libnetlink.h" 24 19 … … 28 23 } 29 24 30 int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)25 int xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/) 31 26 { 32 27 socklen_t addr_len; … … 34 29 memset(rth, 0, sizeof(rth)); 35 30 36 rth->fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); 37 if (rth->fd < 0) { 38 bb_perror_msg("Cannot open netlink socket"); 39 return -1; 40 } 31 rth->fd = xsocket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); 41 32 42 33 memset(&rth->local, 0, sizeof(rth->local)); 43 34 rth->local.nl_family = AF_NETLINK; 44 rth->local.nl_groups = subscriptions; 45 46 if (bind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)) < 0) { 47 bb_perror_msg("Cannot bind netlink socket"); 48 return -1; 49 } 35 /*rth->local.nl_groups = subscriptions;*/ 36 37 xbind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)); 50 38 addr_len = sizeof(rth->local); 51 if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) { 52 bb_perror_msg("Cannot getsockname"); 53 return -1; 54 } 55 if (addr_len != sizeof(rth->local)) { 56 bb_error_msg("Wrong address length %d", addr_len); 57 return -1; 58 } 59 if (rth->local.nl_family != AF_NETLINK) { 60 bb_error_msg("Wrong address family %d", rth->local.nl_family); 61 return -1; 62 } 39 if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) 40 bb_perror_msg_and_die("cannot getsockname"); 41 if (addr_len != sizeof(rth->local)) 42 bb_error_msg_and_die("wrong address length %d", addr_len); 43 if (rth->local.nl_family != AF_NETLINK) 44 bb_error_msg_and_die("wrong address family %d", rth->local.nl_family); 63 45 rth->seq = time(NULL); 64 46 return 0; 65 47 } 66 48 67 int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)49 int xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) 68 50 { 69 51 struct { … … 83 65 req.g.rtgen_family = family; 84 66 85 return sendto(rth->fd, (void*)&req, sizeof(req), 0, (struct sockaddr*)&nladdr, sizeof(nladdr)); 67 return xsendto(rth->fd, (void*)&req, sizeof(req), 68 (struct sockaddr*)&nladdr, sizeof(nladdr)); 86 69 } 87 70 … … 93 76 nladdr.nl_family = AF_NETLINK; 94 77 95 return sendto(rth->fd, buf, len, 0, (struct sockaddr*)&nladdr, sizeof(nladdr));78 return xsendto(rth->fd, buf, len, (struct sockaddr*)&nladdr, sizeof(nladdr)); 96 79 } 97 80 … … 120 103 } 121 104 122 int rtnl_dump_filter(struct rtnl_handle *rth,123 124 void *arg1,125 int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),126 void *arg2)127 { 128 char 105 static int rtnl_dump_filter(struct rtnl_handle *rth, 106 int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *), 107 void *arg1/*, 108 int (*junk)(struct sockaddr_nl *, struct nlmsghdr *n, void *), 109 void *arg2*/) 110 { 111 char buf[8192]; 129 112 struct sockaddr_nl nladdr; 130 113 struct iovec iov = { buf, sizeof(buf) }; … … 164 147 h->nlmsg_pid != rth->local.nl_pid || 165 148 h->nlmsg_seq != rth->dump) { 166 if (junk) {149 /* if (junk) { 167 150 err = junk(&nladdr, h, arg2); 168 if (err < 0) {151 if (err < 0) 169 152 return err; 170 } 171 } 153 } */ 172 154 goto skip_it; 173 155 } … … 187 169 } 188 170 err = filter(&nladdr, h, arg1); 189 if (err < 0) {171 if (err < 0) 190 172 return err; 191 }192 173 193 174 skip_it: … … 195 176 } 196 177 if (msg.msg_flags & MSG_TRUNC) { 197 bb_error_msg(" Message truncated");178 bb_error_msg("message truncated"); 198 179 continue; 199 180 } 200 181 if (status) { 201 bb_error_msg_and_die("!!!Remnant of size %d", status); 202 } 203 } 182 bb_error_msg_and_die("remnant of size %d!", status); 183 } 184 } 185 } 186 187 int xrtnl_dump_filter(struct rtnl_handle *rth, 188 int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *), 189 void *arg1) 190 { 191 int ret = rtnl_dump_filter(rth, filter, arg1/*, NULL, NULL*/); 192 if (ret < 0) 193 bb_error_msg_and_die("dump terminated"); 194 return ret; 204 195 } 205 196 … … 234 225 235 226 if (status < 0) { 236 bb_perror_msg(" Cannot talk to rtnetlink");227 bb_perror_msg("cannot talk to rtnetlink"); 237 228 return -1; 238 229 } … … 265 256 if (l<0 || len>status) { 266 257 if (msg.msg_flags & MSG_TRUNC) { 267 bb_error_msg(" Truncated message");258 bb_error_msg("truncated message"); 268 259 return -1; 269 260 } 270 bb_error_msg_and_die(" !!!malformed message: len=%d", len);261 bb_error_msg_and_die("malformed message: len=%d!", len); 271 262 } 272 263 … … 304 295 } 305 296 306 bb_error_msg(" Unexpected reply!!!");297 bb_error_msg("unexpected reply!"); 307 298 308 299 status -= NLMSG_ALIGN(len); … … 310 301 } 311 302 if (msg.msg_flags & MSG_TRUNC) { 312 bb_error_msg(" Message truncated");303 bb_error_msg("message truncated"); 313 304 continue; 314 305 } 315 306 if (status) { 316 bb_error_msg_and_die(" !!!Remnant of size %d", status);317 } 318 } 319 } 320 321 int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32data)307 bb_error_msg_and_die("remnant of size %d!", status); 308 } 309 } 310 } 311 312 int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data) 322 313 { 323 314 int len = RTA_LENGTH(4); … … 348 339 } 349 340 350 int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32data)341 int rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data) 351 342 { 352 343 int len = RTA_LENGTH(4); … … 390 381 } 391 382 if (len) { 392 bb_error_msg(" !!!Deficit %d, rta_len=%d", len, rta->rta_len);393 } 394 return 0; 395 } 383 bb_error_msg("deficit %d, rta_len=%d!", len, rta->rta_len); 384 } 385 return 0; 386 }
Note:
See TracChangeset
for help on using the changeset viewer.