--- include/inet.h | 3 ++ src/inet.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/include/inet.h b/include/inet.h index 9ba7781..9a9411d 100644 --- a/include/inet.h +++ b/include/inet.h @@ -73,6 +73,9 @@ int connman_inet_clear_ipv6_gateway_address(int index, const char *gateway); int connman_inet_add_to_bridge(int index, const char *bridge); int connman_inet_remove_from_bridge(int index, const char *bridge); +int connman_inet_set_mtu(int index, int mtu); +int connman_inet_setup_tunnel(char *tunnel, int mtu); + #ifdef __cplusplus } #endif diff --git a/src/inet.c b/src/inet.c index fa768fb..8609d9e 100644 --- a/src/inet.c +++ b/src/inet.c @@ -35,8 +35,8 @@ #include <arpa/inet.h> #include <net/route.h> #include <net/ethernet.h> -#include <linux/if_arp.h> -#include <linux/wireless.h> +#include <net/if.h> +#include <net/if_arp.h> #include "connman.h" @@ -1194,3 +1194,70 @@ int connman_inet_add_to_bridge(int index, const char *bridge) return 0; } + +int connman_inet_set_mtu(int index, int mtu) +{ + struct ifreq ifr; + int sk, err; + + sk = socket(AF_INET, SOCK_DGRAM, 0); + if (sk < 0) + return sk; + + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_ifindex = index; + + err = ioctl(sk, SIOCGIFNAME, &ifr); + if (err == 0) { + ifr.ifr_mtu = mtu; + err = ioctl(sk, SIOCSIFMTU, &ifr); + } + + close(sk); + return err; +} + +int connman_inet_setup_tunnel(char *tunnel, int mtu) +{ + struct ifreq ifr; + int sk, err, index; + __u32 mask; + __u32 flags; + + if (tunnel == NULL) + return -EINVAL; + + sk = socket(AF_INET, SOCK_DGRAM, 0); + if (sk < 0) + return sk; + + index = if_nametoindex(tunnel); + + err = connman_inet_set_mtu(index, mtu); + if (err < 0) + return err; + else if (err) + goto done; + + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, tunnel, IFNAMSIZ); + err = ioctl(sk, SIOCGIFFLAGS, &ifr); + if (err) + goto done; + + mask = IFF_UP; + flags = IFF_UP; + + if ((ifr.ifr_flags ^ flags) & mask) { + ifr.ifr_flags &= ~mask; + ifr.ifr_flags |= mask & flags; + err = ioctl(sk, SIOCSIFFLAGS, &ifr); + if (err) + connman_error("SIOCSIFFLAGS failed: %s", + strerror(errno)); + } + +done: + close(sk); + return err; +} -- 1.7.0.4 _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman