diff options
author | Nick Kralevich <nnk@google.com> | 2013-02-23 01:04:16 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2013-02-23 01:04:16 +0000 |
commit | 559230ca44fa6a468d465d932f143ce95d12ab4c (patch) | |
tree | 5d7df7bf495efd599d87ee10181701cd61347c22 | |
parent | f68200ab1a5c559866a87e51d0d52e3c74b02343 (diff) | |
parent | 4f3d78640de4573ced186edd3a09b1247d981edf (diff) | |
download | android_external_android-clat-559230ca44fa6a468d465d932f143ce95d12ab4c.tar.gz android_external_android-clat-559230ca44fa6a468d465d932f143ce95d12ab4c.tar.bz2 android_external_android-clat-559230ca44fa6a468d465d932f143ce95d12ab4c.zip |
Merge "Ensure netlink messages come from the kernel."
-rw-r--r-- | netlink_msg.c | 18 | ||||
-rw-r--r-- | netlink_msg.h | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/netlink_msg.c b/netlink_msg.c index 7363028..2ba237d 100644 --- a/netlink_msg.c +++ b/netlink_msg.c @@ -103,6 +103,21 @@ struct nl_msg *nlmsg_alloc_rtmsg(uint16_t type, uint16_t flags, struct rtmsg *rt return nlmsg_alloc_generic(type, flags, rt, sizeof(*rt)); } +/* function: netlink_set_kernel_only + * sets a socket to receive messages only from the kernel + * sock - socket to connect + */ +int netlink_set_kernel_only(struct nl_sock *nl_sk) { + struct sockaddr_nl addr = { AF_NETLINK, 0, 0, 0 }; + + if (!nl_sk) { + return -EFAULT; + } + + int sockfd = nl_socket_get_fd(nl_sk); + return connect(sockfd, (struct sockaddr *) &addr, sizeof(addr)); +} + /* function: send_netlink_msg * sends a netlink message, reads a response, and hands the response(s) to the callbacks * msg - netlink message to send @@ -121,6 +136,9 @@ void send_netlink_msg(struct nl_msg *msg, struct nl_cb *callbacks) { if(nl_send_auto_complete(nl_sk, msg) < 0) goto cleanup; + if(netlink_set_kernel_only(nl_sk) < 0) + goto cleanup; + nl_recvmsgs(nl_sk, callbacks); cleanup: diff --git a/netlink_msg.h b/netlink_msg.h index bc85b2d..13e1f28 100644 --- a/netlink_msg.h +++ b/netlink_msg.h @@ -25,5 +25,6 @@ struct nl_msg *nlmsg_alloc_rtmsg(uint16_t type, uint16_t flags, struct rtmsg *rt void send_netlink_msg(struct nl_msg *msg, struct nl_cb *callbacks); void send_ifaddrmsg(uint16_t type, uint16_t flags, struct ifaddrmsg *ifa, struct nl_cb *callbacks); int netlink_sendrecv(struct nl_msg *msg); +int netlink_set_kernel_only(struct nl_sock *nl_sk); #endif |