From 3f4beaca9bcea35ffeff810f068487dd449cc2cb Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Thu, 17 Mar 2016 16:27:50 +0300 Subject: ipoe: log warn if interface was not started by vlan_mon notification --- accel-pppd/ctrl/ipoe/ipoe.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'accel-pppd') diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 1e3c04c2..9d3890d5 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -2217,11 +2217,11 @@ void ipoe_vlan_mon_notify(int ifindex, int vid) return; } + log_info2("ipoe: create vlan %s parent %s\n", ifname, ifr.ifr_name); + if (iplink_vlan_add(ifname, ifindex, vid)) return; - log_info2("ipoe: create vlan %s parent %s\n", ifname, ifr.ifr_name); - len = strlen(ifname); memcpy(ifr.ifr_name, ifname, len + 1); @@ -2234,7 +2234,6 @@ void ipoe_vlan_mon_notify(int ifindex, int vid) return; } - list_for_each_entry(opt, §->items, entry) { if (strcmp(opt->name, "interface")) continue; @@ -2264,9 +2263,14 @@ void ipoe_vlan_mon_notify(int ifindex, int vid) continue; add_interface(ifname, ifr.ifr_ifindex, opt->val, ifindex, vid); - } else if (ptr - opt->val == len && memcmp(opt->val, ifname, len) == 0) + return; + } else if (ptr - opt->val == len && memcmp(opt->val, ifname, len) == 0) { add_interface(ifname, ifr.ifr_ifindex, opt->val, ifindex, vid); + return; + } } + + log_warn("ipoe: vlan %s not started\n", ifname); } static void ipoe_serv_timeout(struct triton_timer_t *t) -- cgit v1.2.3 From 61d91047cdbf134c98d414951d84e38ff2adbd34 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Thu, 17 Mar 2016 16:30:52 +0300 Subject: ipoe: fixed possible race condition --- accel-pppd/ctrl/ipoe/ipoe.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'accel-pppd') diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 9d3890d5..30ee87f0 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -1826,6 +1826,7 @@ void ipoe_recv_up(int ifindex, struct ethhdr *eth, struct iphdr *iph) struct ipoe_serv *serv; struct ipoe_session *ses; + pthread_mutex_lock(&serv_lock); list_for_each_entry(serv, &serv_list, entry) { if (serv->ifindex != ifindex) continue; @@ -1846,6 +1847,7 @@ void ipoe_recv_up(int ifindex, struct ethhdr *eth, struct iphdr *iph) break; } + pthread_mutex_unlock(&serv_lock); } #ifdef RADIUS @@ -2407,11 +2409,6 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int close(sock); } - if (opt_up) - ipoe_nl_add_interface(ifindex, opt_mode); - else - ipoe_nl_add_interface(ifindex, 0); - pthread_mutex_lock(&serv_lock); list_for_each_entry(serv, &serv_list, entry) { if (strcmp(ifname, serv->ifname)) @@ -2477,6 +2474,11 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int } pthread_mutex_unlock(&serv_lock); + if (opt_up) + ipoe_nl_add_interface(ifindex, opt_mode); + else + ipoe_nl_add_interface(ifindex, 0); + opt = strchr(opt, ','); if (opt) opt++; -- cgit v1.2.3 From 1709f9496d5a47a45865df9c8328092aeb159bf7 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Thu, 17 Mar 2016 17:23:53 +0300 Subject: ipoe: add missing pthread_mutex_unlock --- accel-pppd/ctrl/ipoe/ipoe.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'accel-pppd') diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 30ee87f0..a0ab5b85 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -1831,13 +1831,16 @@ void ipoe_recv_up(int ifindex, struct ethhdr *eth, struct iphdr *iph) if (serv->ifindex != ifindex) continue; - if (!serv->opt_up) + if (!serv->opt_up) { + pthread_mutex_unlock(&serv_lock); return; + } pthread_mutex_lock(&serv->lock); list_for_each_entry(ses, &serv->sessions, entry) { if (ses->yiaddr == iph->saddr) { pthread_mutex_unlock(&serv->lock); + pthread_mutex_unlock(&serv_lock); return; } } -- cgit v1.2.3 From 9d6f83faa75d8f5091faaa6422420490692660d4 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Thu, 17 Mar 2016 18:07:54 +0300 Subject: ipoe: use local netlink socket in add/del interface functions (fix race condition) --- accel-pppd/ctrl/ipoe/ipoe_netlink.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'accel-pppd') diff --git a/accel-pppd/ctrl/ipoe/ipoe_netlink.c b/accel-pppd/ctrl/ipoe/ipoe_netlink.c index cd2433e9..7e61fb84 100644 --- a/accel-pppd/ctrl/ipoe/ipoe_netlink.c +++ b/accel-pppd/ctrl/ipoe/ipoe_netlink.c @@ -100,6 +100,7 @@ void ipoe_nl_del_exclude(uint32_t addr) void ipoe_nl_add_interface(int ifindex, uint8_t mode) { + struct rtnl_handle rth; struct nlmsghdr *nlh; struct genlmsghdr *ghdr; struct { @@ -107,8 +108,10 @@ void ipoe_nl_add_interface(int ifindex, uint8_t mode) char buf[1024]; } req; - if (rth.fd == -1) + if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) { + log_ppp_error("ipoe: cannot open generic netlink socket\n"); return; + } nlh = &req.n; nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); @@ -123,10 +126,13 @@ void ipoe_nl_add_interface(int ifindex, uint8_t mode) if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 ) log_error("ipoe: nl_add_iface: error talking to kernel\n"); + + rtnl_close(&rth); } void ipoe_nl_del_interface(int ifindex) { + struct rtnl_handle rth; struct nlmsghdr *nlh; struct genlmsghdr *ghdr; struct { @@ -134,8 +140,10 @@ void ipoe_nl_del_interface(int ifindex) char buf[1024]; } req; - if (rth.fd == -1) + if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) { + log_ppp_error("ipoe: cannot open generic netlink socket\n"); return; + } nlh = &req.n; nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); @@ -149,6 +157,8 @@ void ipoe_nl_del_interface(int ifindex) if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 ) log_error("ipoe: nl_del_iface: error talking to kernel\n"); + + rtnl_close(&rth); } void ipoe_nl_delete_interfaces(void) -- cgit v1.2.3