--- debian/changelog | 2 ++ netcfg-common.c | 1 + netcfg.h | 3 +++ vlan.c | 16 ++++++++-------- write_interface.c | 15 +++++++-------- 5 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/debian/changelog b/debian/changelog index 2a5e4e6..7b7aebe 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,8 @@ netcfg (1.138) UNRELEASED; urgency=medium * nm-conf.c: check return result of fscanf * Makefile: link with -lm to resolve undefined log and other functions * All of above resolves FTBFS + * Impove vlan support, by not relying on '.' to detect and write out + vlan raw device stanza -- Dimitri John Ledkov <x...@ubuntu.com> Wed, 30 Mar 2016 12:13:56 +0100 diff --git a/netcfg-common.c b/netcfg-common.c index c6d1d8d..8d69b5e 100644 --- a/netcfg-common.c +++ b/netcfg-common.c @@ -1564,6 +1564,7 @@ void netcfg_interface_init(struct netcfg_interface *iface) iface->v6_stateless_config = -1; iface->loopback = -1; iface->mode = MANAGED; + iface->vlan_raw_device = NULL; } /* Parse an IP address (v4 or v6), with optional CIDR netmask, into diff --git a/netcfg.h b/netcfg.h index 4dfbdee..65c97d7 100644 --- a/netcfg.h +++ b/netcfg.h @@ -151,6 +151,9 @@ struct netcfg_interface { /* WPA */ wpa_t wpa_supplicant_status; char *passphrase; + + /* VLAN */ + char *vlan_raw_device; }; /* Somewhere we can store both in_addr and in6_addr; convenient for all those diff --git a/vlan.c b/vlan.c index ec2a19b..a96c9c6 100644 --- a/vlan.c +++ b/vlan.c @@ -14,8 +14,8 @@ int netcfg_set_vlan(struct netcfg_interface *interface, struct debconfclient *cl char vlancmd_template[] = "ip link add link %s name %s type vlan id %s"; #elif defined(__FreeBSD_kernel__) /*export 2 more to make it the same formt with Linux*/ - char vlancmd_tmplate[] = "export NIC=%s; export VNIC=%s; export VLANID=%s;" - " ifconfig $VNIC create"; + char vlancmd_tmplate[] = "export NIC=%s; export VNIC=%s; export VLANID=%s;" + " ifconfig $VNIC create"; #endif int vlancmd_template_len = sizeof(vlancmd_template); @@ -47,15 +47,15 @@ int netcfg_set_vlan(struct netcfg_interface *interface, struct debconfclient *cl snprintf(vlancmd, vlancmd_len, vlancmd_template, interface->name, vlaniface, vlanid); if(di_exec_shell_log(vlancmd)){ di_warning("^ Setting VLAN error: the command is \n%s", vlancmd); - debconf_capb(client); - debconf_input(client, "critical", "netcfg/vlan_cmderror"); - debconf_go(client); - debconf_capb(client, "backup"); + debconf_capb(client); + debconf_input(client, "critical", "netcfg/vlan_cmderror"); + debconf_go(client); + debconf_capb(client, "backup"); goto error; } if(interface->name){ - free(interface->name); - interface->name = vlaniface; + interface->vlan_raw_device = interface->name; + interface->name = vlaniface; } free(vlancmd); return VLAN_SUCESSED; diff --git a/write_interface.c b/write_interface.c index be0d78b..09f9848 100644 --- a/write_interface.c +++ b/write_interface.c @@ -48,14 +48,13 @@ static int nc_wi_loopback(const struct netcfg_interface *interface, FILE *fd) */ static int nc_wi_vlan(const struct netcfg_interface *interface, FILE *fd) { - char *dup_name, *strip_name; - dup_name = strdup(interface->name); - strip_name = strsep(&dup_name, "."); - if(strip_name != NULL){ - fprintf(fd, "\tvlan_raw_device %s\n", strip_name); + int rv; + rv = 1; + if (interface && interface->vlan_raw_device && + (fprintf(fd, "\tvlan_raw_device %s\n", interface->vlan_raw_device) < 0)) { + rv = 0; } - free(dup_name); - return 1; + return rv; } @@ -286,7 +285,7 @@ int netcfg_write_interface(const struct netcfg_interface *interface) di_debug("Writing static IPv6 stanza for %s", interface->name); rv = nc_wi_static_ipv6(interface, fd); } - if (rv && strchr(interface->name, '.')){ + if (rv && interface && interface->vlan_raw_device) { di_debug("Writing VLAN: %s", interface->name); rv = nc_wi_vlan(interface, fd); } -- 2.7.4