libmnl  1.0.4
fib-test.c
1 /* Test to crash netlink with large vmalloc'ed skbuff */
2 #include <netinet/in.h>
3 #include <arpa/inet.h>
4 #include <time.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <strings.h>
9 #include <net/if.h>
10 
11 #include <libmnl/libmnl.h>
12 #include <linux/if_link.h>
13 #include <linux/rtnetlink.h>
14 
15 int main(int argc, char *argv[])
16 {
17  struct mnl_socket *nl;
18  char buf[MNL_SOCKET_BUFFER_SIZE*4];
19  struct nlmsghdr *nlh;
20  struct rtmsg *rtm;
21  uint32_t prefix, seq, portid;
22  int ret;
23 
24  nlh = mnl_nlmsg_put_header(buf);
25  nlh->nlmsg_type = RTM_NEWROUTE;
26  nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK;
27  nlh->nlmsg_seq = seq = time(NULL);
28  nlh->nlmsg_len += sizeof(buf) - sizeof(struct nlmsghdr);
29 
30  nl = mnl_socket_open(NETLINK_FIB_LOOKUP);
31  if (nl == NULL) {
32  perror("mnl_socket_open");
33  exit(EXIT_FAILURE);
34  }
35 
36  if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
37  perror("mnl_socket_bind");
38  exit(EXIT_FAILURE);
39  }
40  portid = mnl_socket_get_portid(nl);
41 
42  /* Send garbage, don't care */
43  if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
44  perror("mnl_socket_send");
45  exit(EXIT_FAILURE);
46  }
47 
48  ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
49  if (ret < 0) {
50  perror("mnl_socket_recvfrom");
51  exit(EXIT_FAILURE);
52  }
53 
54  ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
55  if (ret < 0) {
56  perror("mnl_cb_run");
57  exit(EXIT_FAILURE);
58  }
59 
60  mnl_socket_close(nl);
61 
62  return 0;
63 }