diff options
author | Rene Mayrhofer <rene@mayrhofer.eu.org> | 2008-07-09 21:02:41 +0000 |
---|---|---|
committer | Rene Mayrhofer <rene@mayrhofer.eu.org> | 2008-07-09 21:02:41 +0000 |
commit | db67c87db3c9089ea8d2e14f617bf3d9e2af261f (patch) | |
tree | 665c0caea83d34c11c1517c4c57137bb58cba6fb /src/dumm/iface.c | |
parent | 1c088a8b6237ec67f63c23f97a0f2dc4e99af869 (diff) | |
download | vyos-strongswan-db67c87db3c9089ea8d2e14f617bf3d9e2af261f.tar.gz vyos-strongswan-db67c87db3c9089ea8d2e14f617bf3d9e2af261f.zip |
[svn-upgrade] Integrating new upstream version, strongswan (4.2.4)
Diffstat (limited to 'src/dumm/iface.c')
-rw-r--r-- | src/dumm/iface.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/dumm/iface.c b/src/dumm/iface.c index 3c1bfc470..b78c10bec 100644 --- a/src/dumm/iface.c +++ b/src/dumm/iface.c @@ -44,6 +44,42 @@ struct private_iface_t { }; /** + * bring an interface up or down + */ +bool iface_control(char *name, bool up) +{ + int s; + bool good = FALSE; + struct ifreq ifr; + + memset(&ifr, 0, sizeof(struct ifreq)); + strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (!s) + { + return FALSE; + } + if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) + { + if (up) + { + ifr.ifr_flags |= IFF_UP; + } + else + { + ifr.ifr_flags &= ~IFF_UP; + } + if (ioctl(s, SIOCSIFFLAGS, &ifr) == 0) + { + good = TRUE; + } + } + close(s); + return good; +} + +/** * Implementation of iface_t.get_guestif. */ static char* get_guestif(private_iface_t *this) @@ -74,7 +110,11 @@ static bool destroy_tap(private_iface_t *this) { struct ifreq ifr; int tap; - + + if (!iface_control(this->hostif, FALSE)) + { + DBG1("bringing iface down failed: %m"); + } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; strncpy(ifr.ifr_name, this->hostif, sizeof(ifr.ifr_name) - 1); @@ -165,6 +205,10 @@ iface_t *iface_create(char *guest, char *guestif, mconsole_t *mconsole) free(this); return NULL; } + if (!iface_control(this->hostif, TRUE)) + { + DBG1("bringing iface '%s' up failed: %m", this->hostif); + } if (!this->mconsole->add_iface(this->mconsole, this->guestif, this->hostif)) { DBG1("creating interface '%s' in guest failed", this->guestif); |