26 |
{ |
{ |
27 |
socklen_t addr_len; |
socklen_t addr_len; |
28 |
|
|
29 |
memset(rth, 0, sizeof(rth)); |
memset(rth, 0, sizeof(*rth)); |
|
|
|
30 |
rth->fd = xsocket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); |
rth->fd = xsocket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); |
|
|
|
|
memset(&rth->local, 0, sizeof(rth->local)); |
|
31 |
rth->local.nl_family = AF_NETLINK; |
rth->local.nl_family = AF_NETLINK; |
32 |
/*rth->local.nl_groups = subscriptions;*/ |
/*rth->local.nl_groups = subscriptions;*/ |
33 |
|
|
34 |
xbind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)); |
xbind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)); |
35 |
addr_len = sizeof(rth->local); |
addr_len = sizeof(rth->local); |
36 |
|
getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len); |
37 |
|
|
38 |
|
/* too much paranoia |
39 |
if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) |
if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) |
40 |
bb_perror_msg_and_die("getsockname"); |
bb_perror_msg_and_die("getsockname"); |
41 |
if (addr_len != sizeof(rth->local)) |
if (addr_len != sizeof(rth->local)) |
42 |
bb_error_msg_and_die("wrong address length %d", addr_len); |
bb_error_msg_and_die("wrong address length %d", addr_len); |
43 |
if (rth->local.nl_family != AF_NETLINK) |
if (rth->local.nl_family != AF_NETLINK) |
44 |
bb_error_msg_and_die("wrong address family %d", rth->local.nl_family); |
bb_error_msg_and_die("wrong address family %d", rth->local.nl_family); |
45 |
|
*/ |
46 |
rth->seq = time(NULL); |
rth->seq = time(NULL); |
47 |
return 0; |
return 0; |
48 |
} |
} |
104 |
} |
} |
105 |
|
|
106 |
static int rtnl_dump_filter(struct rtnl_handle *rth, |
static int rtnl_dump_filter(struct rtnl_handle *rth, |
107 |
int (*filter)(const struct sockaddr_nl *, struct nlmsghdr *n, void *), |
int (*filter)(const struct sockaddr_nl *, struct nlmsghdr *n, void *) FAST_FUNC, |
108 |
void *arg1/*, |
void *arg1/*, |
109 |
int (*junk)(struct sockaddr_nl *, struct nlmsghdr *n, void *), |
int (*junk)(struct sockaddr_nl *, struct nlmsghdr *n, void *), |
110 |
void *arg2*/) |
void *arg2*/) |
196 |
} |
} |
197 |
|
|
198 |
int FAST_FUNC xrtnl_dump_filter(struct rtnl_handle *rth, |
int FAST_FUNC xrtnl_dump_filter(struct rtnl_handle *rth, |
199 |
int (*filter)(const struct sockaddr_nl *, struct nlmsghdr *, void *), |
int (*filter)(const struct sockaddr_nl *, struct nlmsghdr *, void *) FAST_FUNC, |
200 |
void *arg1) |
void *arg1) |
201 |
{ |
{ |
202 |
int ret = rtnl_dump_filter(rth, filter, arg1/*, NULL, NULL*/); |
int ret = rtnl_dump_filter(rth, filter, arg1/*, NULL, NULL*/); |
206 |
} |
} |
207 |
|
|
208 |
int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, |
int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, |
209 |
pid_t peer, unsigned groups, |
pid_t peer, unsigned groups, |
210 |
struct nlmsghdr *answer, |
struct nlmsghdr *answer, |
211 |
int (*junk)(struct sockaddr_nl *, struct nlmsghdr *, void *), |
int (*junk)(struct sockaddr_nl *, struct nlmsghdr *, void *), |
212 |
void *jarg) |
void *jarg) |
213 |
{ |
{ |
214 |
/* bbox doesn't use parameters no. 3, 4, 6, 7, they are stubbed out */ |
/* bbox doesn't use parameters no. 3, 4, 6, 7, they are stubbed out */ |
215 |
#define peer 0 |
#define peer 0 |
242 |
status = sendmsg(rtnl->fd, &msg, 0); |
status = sendmsg(rtnl->fd, &msg, 0); |
243 |
|
|
244 |
if (status < 0) { |
if (status < 0) { |
245 |
bb_perror_msg("cannot talk to rtnetlink"); |
bb_perror_msg("can't talk to rtnetlink"); |
246 |
goto ret; |
goto ret; |
247 |
} |
} |
248 |
|
|
342 |
rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); |
rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); |
343 |
rta->rta_type = type; |
rta->rta_type = type; |
344 |
rta->rta_len = len; |
rta->rta_len = len; |
345 |
memcpy(RTA_DATA(rta), &data, 4); |
move_to_unaligned32(RTA_DATA(rta), data); |
346 |
n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len; |
n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len; |
347 |
return 0; |
return 0; |
348 |
} |
} |
373 |
subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len)); |
subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len)); |
374 |
subrta->rta_type = type; |
subrta->rta_type = type; |
375 |
subrta->rta_len = len; |
subrta->rta_len = len; |
376 |
memcpy(RTA_DATA(subrta), &data, 4); |
move_to_unaligned32(RTA_DATA(subrta), data); |
377 |
rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len; |
rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len; |
378 |
return 0; |
return 0; |
379 |
} |
} |