}
static int create_matched_ifnames(const char *value, struct lxc_conf *lxc_conf,
- struct lxc_netdev *netdev)
+ struct lxc_netdev *netdev)
{
struct ifaddrs *ifaddr, *ifa;
int n;
return -1;
new_value = strdup(value);
- if (!new_value) {
- SYSERROR("failed to strdup \"%s\"", value);
+ if (!new_value)
return -1;
- }
+
rand_complete_hwaddr(new_value);
if (lxc_config_value_empty(new_value)) {
static int set_config_net_vlan_id(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
+ int ret;
struct lxc_netdev *netdev;
if (lxc_config_value_empty(value))
if (!netdev)
return -1;
- if (get_u16(&netdev->priv.vlan_attr.vid, value, 0))
+ ret = get_u16(&netdev->priv.vlan_attr.vid, value, 0);
+ if (ret < 0)
return -1;
return 0;
static int set_config_net_ipv4_address(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
+ int ret;
struct lxc_netdev *netdev;
struct lxc_inetdev *inetdev;
struct lxc_list *list;
return -1;
inetdev = malloc(sizeof(*inetdev));
- if (!inetdev) {
- SYSERROR("failed to allocate ipv4 address");
+ if (!inetdev)
return -1;
- }
+
memset(inetdev, 0, sizeof(*inetdev));
list = malloc(sizeof(*list));
if (!list) {
- SYSERROR("failed to allocate memory");
free(inetdev);
return -1;
}
addr = strdup(value);
if (!addr) {
- ERROR("no address specified");
free(inetdev);
free(list);
return -1;
prefix = slash + 1;
}
- if (!inet_pton(AF_INET, addr, &inetdev->addr)) {
- SYSERROR("invalid ipv4 address: %s", value);
+ ret = inet_pton(AF_INET, addr, &inetdev->addr);
+ if (!ret || ret < 0) {
+ SYSERROR("Invalid ipv4 address \"%s\"", value);
free(inetdev);
free(addr);
free(list);
return -1;
}
- if (bcast && !inet_pton(AF_INET, bcast, &inetdev->bcast)) {
- SYSERROR("invalid ipv4 broadcast address: %s", value);
- free(inetdev);
- free(list);
- free(addr);
- return -1;
+ if (bcast) {
+ ret = inet_pton(AF_INET, bcast, &inetdev->bcast);
+ if (!ret || ret < 0) {
+ SYSERROR("Invalid ipv4 broadcast address \"%s\"", value);
+ free(inetdev);
+ free(list);
+ free(addr);
+ return -1;
+ }
+
}
/* No prefix specified, determine it from the network class. */
if (prefix) {
- if (lxc_safe_uint(prefix, &inetdev->prefix) < 0)
+ ret = lxc_safe_uint(prefix, &inetdev->prefix);
+ if (ret < 0)
return -1;
} else {
inetdev->prefix = config_ip_prefix(&inetdev->addr);
*/
if (!bcast) {
inetdev->bcast.s_addr = inetdev->addr.s_addr;
- inetdev->bcast.s_addr |=
- htonl(INADDR_BROADCAST >> inetdev->prefix);
+ inetdev->bcast.s_addr |= htonl(INADDR_BROADCAST >> inetdev->prefix);
}
lxc_list_add_tail(&netdev->ipv4, list);