Netlink bugfixes.

Signed-off-by: Benjamin Cama <benoar@dolka.fr>
This commit is contained in:
Benjamin Cama 2011-08-16 00:12:23 +02:00
parent 7aa8cc3dc0
commit c23922ce7c

View file

@ -617,7 +617,6 @@ static void inittun(void)
struct ifinfomsg ifinfo; struct ifinfomsg ifinfo;
struct ifreq ifr; struct ifreq ifr;
char buf[4096]; char buf[4096];
struct nlmsghdr resp_nh;
memset(&ifr, 0, sizeof(ifr)); memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TUN; ifr.ifr_flags = IFF_TUN;
@ -649,6 +648,7 @@ static void inittun(void)
struct rtattr ifname_rta __attribute__ ((aligned(RTA_ALIGNTO))); struct rtattr ifname_rta __attribute__ ((aligned(RTA_ALIGNTO)));
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
} req; } req;
struct nlmsghdr *resp_nh;
req.nh.nlmsg_type = RTM_GETLINK; req.nh.nlmsg_type = RTM_GETLINK;
req.nh.nlmsg_flags = NLM_F_REQUEST; req.nh.nlmsg_flags = NLM_F_REQUEST;
@ -666,7 +666,7 @@ static void inittun(void)
} }
resp_nh = (struct nlmsghdr *)buf; resp_nh = (struct nlmsghdr *)buf;
if (NLMSG_OK (resp_nh, len) && resp_nh.nlmsg_type == RTM_GETLINK) if (NLMSG_OK (resp_nh, len) && resp_nh->nlmsg_type == RTM_GETLINK)
{ {
memcpy(&ifinfo, NLMSG_DATA(resp_nh), sizeof(ifinfo)); memcpy(&ifinfo, NLMSG_DATA(resp_nh), sizeof(ifinfo));
// got index // got index
@ -732,7 +732,7 @@ static void inittun(void)
req.mtu = MRU; req.mtu = MRU;
req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.ifinfo) req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.ifinfo)
+ req.txqlen_rla.rta_len + req.txqlen_rta.rta_len
+ req.mtu_rta.rta_len); + req.mtu_rta.rta_len);
req.addr_nh.nlmsg_type = RTM_NEWADDR; req.addr_nh.nlmsg_type = RTM_NEWADDR;
@ -799,6 +799,7 @@ static void inittun(void)
} }
if (netlink_send(&req.nh, 1) < 0) if (netlink_send(&req.nh, 1) < 0)
{
LOG(0, 0, 0, "Error setting up tun device: %s\n", strerror(errno)); LOG(0, 0, 0, "Error setting up tun device: %s\n", strerror(errno));
exit(1); exit(1);
} }
@ -809,13 +810,12 @@ static void inittun(void)
exit(1); exit(1);
} }
resp_nh = (struct nlmsghdr *)buf; if ((err = netlink_check_ack((struct nlmsghdr *)buf, 4)))
if ((err = netlink_check_ack(resp_nh, 4)))
{ {
if (err < 0) if (err < 0)
LOG(0, 0, 0, "Error while receiving tun device ack: %s\n", strerror(errno)); LOG(0, 0, 0, "Error while receiving tun device ack: %s\n", strerror(errno));
else else
LOG(0, 0, 0, "Error while receiving tun device ack\n", strerror(errno)); LOG(0, 0, 0, "Error while receiving tun device ack\n");
exit(1); exit(1);
} }
} }
@ -4733,6 +4733,8 @@ int main(int argc, char *argv[])
} }
} }
initnetlink();
/* Set up the cluster communications port. */ /* Set up the cluster communications port. */
if (cluster_init() < 0) if (cluster_init() < 0)
exit(1); exit(1);