diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2016-03-17 22:24:19 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2016-03-17 22:24:26 +0300 |
commit | cc9e2a49061b2a77a51e27ed23c8040626a2083b (patch) | |
tree | a906d60e21d789d9d7a88825ada70be0622ecca4 /accel-pppd/ctrl/ipoe | |
parent | ea7f988b40c03a21571143be30200f77450f3ba4 (diff) | |
download | accel-ppp-cc9e2a49061b2a77a51e27ed23c8040626a2083b.tar.gz accel-ppp-cc9e2a49061b2a77a51e27ed23c8040626a2083b.zip |
vlan_mon,ipoe,pppoe: implemented detection of vlan existance
Diffstat (limited to 'accel-pppd/ctrl/ipoe')
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 1e3c04c2..68841fef 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -2181,7 +2181,7 @@ static int get_offer_delay() return 0; } -void ipoe_vlan_mon_notify(int ifindex, int vid) +void ipoe_vlan_mon_notify(int ifindex, int vid, int vlan_ifindex) { struct conf_sect_t *sect = conf_get_section("ipoe"); struct conf_option_t *opt; @@ -2217,24 +2217,59 @@ void ipoe_vlan_mon_notify(int ifindex, int vid) return; } - if (iplink_vlan_add(ifname, ifindex, vid)) - return; + if (vlan_ifindex) { + struct ipoe_serv *serv; + + pthread_mutex_lock(&serv_lock); + list_for_each_entry(serv, &serv_list, entry) { + if (serv->ifindex == vlan_ifindex) { + pthread_mutex_unlock(&serv_lock); + return; + } + } + pthread_mutex_unlock(&serv_lock); + + log_info2("ipoe: create vlan %s parent %s\n", ifname, ifr.ifr_name); + + ifr.ifr_ifindex = vlan_ifindex; + if (ioctl(sock_fd, SIOCGIFNAME, &ifr, sizeof(ifr))) { + log_error("ipoe: vlan-mon: failed to get interface name, ifindex=%i\n", ifindex); + return; + } + + if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr, sizeof(ifr))) + return; + + if (ifr.ifr_flags & IFF_UP) { + ifr.ifr_flags &= ~IFF_UP; + + if (ioctl(sock_fd, SIOCSIFFLAGS, &ifr, sizeof(ifr))) + return; + } + + if (strcmp(ifr.ifr_name, ifname)) { + strcpy(ifr.ifr_newname, ifname); + if (ioctl(sock_fd, SIOCSIFNAME, &ifr, sizeof(ifr))) { + log_error("ipoe: vlan-mon: failed to rename interface %s to %s\n", ifr.ifr_name, ifr.ifr_newname); + return; + } + strcpy(ifr.ifr_name, ifname); + } + } else { + log_info2("ipoe: create vlan %s parent %s\n", ifname, ifr.ifr_name); - log_info2("ipoe: create vlan %s parent %s\n", ifname, ifr.ifr_name); + if (iplink_vlan_add(ifname, ifindex, vid)) + return; + } len = strlen(ifname); memcpy(ifr.ifr_name, ifname, len + 1); - ioctl(sock_fd, SIOCGIFFLAGS, &ifr, sizeof(ifr)); - ifr.ifr_flags |= IFF_UP; - ioctl(sock_fd, SIOCSIFFLAGS, &ifr, sizeof(ifr)); - if (ioctl(sock_fd, SIOCGIFINDEX, &ifr, sizeof(ifr))) { log_error("ipoe: vlan-mon: %s: failed to get interface index\n", ifr.ifr_name); return; } - list_for_each_entry(opt, §->items, entry) { if (strcmp(opt->name, "interface")) continue; @@ -2482,6 +2517,10 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, ifname); + ((struct sockaddr_in *)&ifr.ifr_addr)->sin_family = AF_INET; + + ioctl(sock_fd, SIOCSIFADDR, &ifr, sizeof(ifr)); + if (ioctl(sock_fd, SIOCGIFHWADDR, &ifr)) { log_error("ipoe: '%s': ioctl(SIOCGIFHWADDR): %s\n", ifname, strerror(errno)); return; @@ -2489,12 +2528,14 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int ioctl(sock_fd, SIOCGIFFLAGS, &ifr); - if (!(ifr.ifr_flags & IFF_UP)) { - ifr.ifr_flags |= IFF_UP; - + if (ifr.ifr_flags & IFF_UP) { + ifr.ifr_flags &= ~IFF_UP; ioctl(sock_fd, SIOCSIFFLAGS, &ifr); } + ifr.ifr_flags |= IFF_UP; + ioctl(sock_fd, SIOCSIFFLAGS, &ifr); + serv = _malloc(sizeof(*serv)); memset(serv, 0, sizeof(*serv)); serv->ctx.close = ipoe_serv_close; |