summaryrefslogtreecommitdiffstats
path: root/examples/genl-family-get.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2010-04-04 02:32:35 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2010-04-04 15:58:54 +0200
commit117f033c413820739e6679c926a39a5b3f45ff79 (patch)
treefd8ed9da15216992570be27ee55eafb235457fcb /examples/genl-family-get.c
parent8ce5d4ca70884654988eb86734cb3022e0b71995 (diff)
check source of the netlink message and fix sequence tracking logic
This patch changes the callback handlers to include netlink portID checking. Thus, we avoid that any malicious process can spoof messages. If portid, sequence number of the message is != 0, we check if the message is what we expect. This allows to use the same netlink channel for dumps (portid, seq != 0) and event-based notifications (portid, seq == 0). Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'examples/genl-family-get.c')
-rw-r--r--examples/genl-family-get.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/examples/genl-family-get.c b/examples/genl-family-get.c
index 00f601c..fbe1bf1 100644
--- a/examples/genl-family-get.c
+++ b/examples/genl-family-get.c
@@ -187,7 +187,7 @@ int main(int argc, char *argv[])
struct nlmsghdr *nlh;
struct genlmsghdr *genl;
int ret;
- unsigned int seq;
+ unsigned int seq, portid;
if (argc != 2) {
printf("%s [family name]\n", argv[0]);
@@ -216,6 +216,7 @@ int main(int argc, char *argv[])
perror("mnl_socket_bind");
exit(EXIT_FAILURE);
}
+ portid = mnl_socket_get_portid(nl);
if (mnl_socket_sendto(nl, nlh, mnl_nlmsg_get_len(nlh)) < 0) {
perror("mnl_socket_send");
@@ -224,7 +225,7 @@ int main(int argc, char *argv[])
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
while (ret > 0) {
- ret = mnl_cb_run(buf, ret, seq, data_cb, NULL);
+ ret = mnl_cb_run(buf, ret, seq, portid, data_cb, NULL);
if (ret <= 0)
break;
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));