#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <sys/wait.h>
#include <string.h>
#include <signal.h>
#include <fcntl.h>
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, vpninfo->ifname, sizeof(ifr.ifr_name) - 1);
- ifr.ifr_mtu = vpninfo->mtu;
+ ifr.ifr_mtu = vpninfo->actual_mtu;
if (ioctl(net_fd, SIOCSIFMTU, &ifr) < 0)
perror(_("SIOCSIFMTU"));
unsetenv("CISCO_SPLIT_INC");
unsetenv("CISCO_SPLIT_EXC");
- setenv_int("INTERNAL_IP4_MTU", vpninfo->mtu);
+ setenv_int("INTERNAL_IP4_MTU", vpninfo->actual_mtu);
if (vpninfo->vpn_addr) {
setenv("INTERNAL_IP4_ADDRESS", vpninfo->vpn_addr, 1);
if (vpninfo->vpn_proxy_pac)
setenv("CISCO_PROXY_PAC", vpninfo->vpn_proxy_pac, 1);
+ if (vpninfo->split_dns) {
+ char *list;
+ int len = 0;
+ struct split_include *dns = vpninfo->split_dns;
+
+ while (dns) {
+ len += strlen(dns->route) + 1;
+ dns = dns->next;
+ }
+ list = malloc(len);
+ if (list) {
+ char *p = list;
+
+ dns = vpninfo->split_dns;
+ while (1) {
+ strcpy(p, dns->route);
+ p += strlen(p);
+ dns = dns->next;
+ if (!dns)
+ break;
+ *(p++) = ',';
+ }
+ setenv("CISCO_SPLIT_DNS", list, 1);
+ free(list);
+ }
+ }
if (vpninfo->split_includes) {
struct split_include *this = vpninfo->split_includes;
int nr_split_includes = 0;
int script_config_tun(struct openconnect_info *vpninfo, const char *reason)
{
+ int ret;
+
if (!vpninfo->vpnc_script)
return 0;
setenv("reason", reason, 1);
- if (system(vpninfo->vpnc_script)) {
+ ret = system(vpninfo->vpnc_script);
+ if (ret == -1) {
int e = errno;
vpn_progress(vpninfo, PRG_ERR,
_("Failed to spawn script '%s' for %s: %s\n"),
vpninfo->vpnc_script, reason, strerror(e));
return -e;
}
+ if (!WIFEXITED(ret)) {
+ vpn_progress(vpninfo, PRG_ERR,
+ _("Script '%s' exited abnormally (%x)\n"),
+ vpninfo->vpnc_script, ret);
+ return -EIO;
+ }
+ ret = WEXITSTATUS(ret);
+ if (ret) {
+ vpn_progress(vpninfo, PRG_ERR,
+ _("Script '%s' returned error %d\n"),
+ vpninfo->vpnc_script, ret);
+ return -EIO;
+ }
return 0;
}
if (tun_fd < 0) {
/* If the error on /dev/tun is ENOENT, that's boring.
Use the error we got on /dev/net/tun instead */
- if (errno != -ENOENT)
+ if (errno != ENOENT)
tunerr = errno;
vpn_progress(vpninfo, PRG_ERR,
if (FD_ISSET(vpninfo->tun_fd, &vpninfo->select_rfds)) {
while (1) {
- int len = vpninfo->mtu;
+ int len = vpninfo->actual_mtu;
if (!out_pkt) {
out_pkt = malloc(sizeof(struct pkt) + len);