Skip to content

Commit

Permalink
[usb-moded] Fix crash in case we have issues with connman/config
Browse files Browse the repository at this point in the history
In case we do not get correct info from connman, and not default nat
interface has been set we could crash. Now we return a mode setting failure

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Mar 14, 2014
1 parent 7421751 commit dabdb24
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/usb_moded-network.c
Expand Up @@ -96,17 +96,22 @@ static char* get_interface(struct mode_list_elem *data)

/**
* Turn on ip forwarding on the usb interface
* @return: 0 on success, 1 on failure
*/
static void set_usb_ip_forward(struct mode_list_elem *data, struct ipforward_data *ipforward)
static int set_usb_ip_forward(struct mode_list_elem *data, struct ipforward_data *ipforward)
{
const char *interface, *nat_interface;
char command[128];

interface = get_interface(data);
nat_interface = get_network_nat_interface();
if(nat_interface == NULL)
if((nat_interface == NULL) && (ipforward->nat_interface != NULL))
nat_interface = strdup(ipforward->nat_interface);

else
{
log_debug("No nat interface available!\n");
return(1);
}
write_to_file("/proc/sys/net/ipv4/ip_forward", "1");
snprintf(command, 128, "/sbin/iptables -t nat -A POSTROUTING -o %s -j MASQUERADE", nat_interface);
system(command);
Expand All @@ -120,6 +125,7 @@ static void set_usb_ip_forward(struct mode_list_elem *data, struct ipforward_dat
free((char *)interface);
free((char *)nat_interface);
log_debug("ipforwarding success!\n");
return(0);
}

/**
Expand Down Expand Up @@ -613,9 +619,7 @@ int usb_network_set_up_dhcpd(struct mode_list_elem *data)
write_udhcpd_conf(ipforward, data);

if(data->nat)
set_usb_ip_forward(data, ipforward);
ret = 0;

ret = set_usb_ip_forward(data, ipforward);

end:
/* the function checks if ipforward is NULL or not */
Expand Down

0 comments on commit dabdb24

Please sign in to comment.