summaryrefslogtreecommitdiff
path: root/accel-pppd/ifcfg.c
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2015-11-24 11:47:43 +0300
committerDmitry Kozlov <xeb@mail.ru>2015-11-24 11:47:43 +0300
commit19dc965d29c7ec17929b8713d021b76107fdf557 (patch)
tree9cbdb9481c791b840bfdc684bbce6620b61e5818 /accel-pppd/ifcfg.c
parentdd0d5ed51e5351d7be2cbdf86b04965b7bcb136b (diff)
parent9b79c7978796c0be8e443863bc277390353e5eaa (diff)
downloadaccel-ppp-19dc965d29c7ec17929b8713d021b76107fdf557.tar.gz
accel-ppp-19dc965d29c7ec17929b8713d021b76107fdf557.zip
Merge branch 'master' of /home/dima/Projects/accel-ppp into vlanmon
Diffstat (limited to 'accel-pppd/ifcfg.c')
-rw-r--r--accel-pppd/ifcfg.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/accel-pppd/ifcfg.c b/accel-pppd/ifcfg.c
index 77a37321..69b77e79 100644
--- a/accel-pppd/ifcfg.c
+++ b/accel-pppd/ifcfg.c
@@ -261,6 +261,7 @@ void __export ap_session_ifdown(struct ap_session *ses)
int __export ap_session_rename(struct ap_session *ses, const char *ifname, int len)
{
struct ifreq ifr;
+ int r, up = 0;
if (len == -1)
len = strlen(ifname);
@@ -274,19 +275,36 @@ int __export ap_session_rename(struct ap_session *ses, const char *ifname, int l
memcpy(ifr.ifr_newname, ifname, len);
ifr.ifr_newname[len] = 0;
- if (ioctl(sock_fd, SIOCSIFNAME, &ifr)) {
+ r = ioctl(sock_fd, SIOCSIFNAME, &ifr);
+ if (r && errno == EBUSY) {
+ ioctl(sock_fd, SIOCGIFFLAGS, &ifr);
+ ifr.ifr_flags &= ~IFF_UP;
+ ioctl(sock_fd, SIOCSIFFLAGS, &ifr);
+
+ memcpy(ifr.ifr_newname, ifname, len);
+ ifr.ifr_newname[len] = 0;
+ r = ioctl(sock_fd, SIOCSIFNAME, &ifr);
+
+ up = 1;
+ }
+
+ if (r) {
if (!ses->ifname_rename)
ses->ifname_rename = _strdup(ifr.ifr_newname);
- else {
+ else
log_ppp_warn("interface rename failed: %s\n", strerror(errno));
- return -1;
- }
} else {
log_ppp_info2("rename interface to '%s'\n", ifr.ifr_newname);
memcpy(ses->ifname, ifname, len);
ses->ifname[len] = 0;
}
- return 0;
+ if (up) {
+ strcpy(ifr.ifr_name, ses->ifname);
+ ifr.ifr_flags |= IFF_UP;
+ ioctl(sock_fd, SIOCSIFFLAGS, &ifr);
+ }
+
+ return r;
}