support ipv4 broadcast specification

Add the broadcast specification, if none is specified, it is automatically
computed from the addr & mask.

syntax:
	lxc.network.ipv4 = 172.20.0.2/24 172.20.255.255

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
Daniel Lezcano 2010-05-18 17:40:04 +02:00 committed by Daniel Lezcano
parent 9232212afd
commit 1f1b18e754
2 changed files with 69 additions and 46 deletions

View File

@ -699,7 +699,8 @@ int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr)
return 0;
}
int lxc_ip_addr_add(int family, int ifindex, void *addr, int prefix)
static int ip_addr_add(int family, int ifindex,
void *addr, void *bcast, void *acast, int prefix)
{
struct nl_handler nlh;
struct nlmsg *nlmsg = NULL, *answer = NULL;
@ -724,7 +725,8 @@ int lxc_ip_addr_add(int family, int ifindex, void *addr, int prefix)
goto out;
ip_req = (struct ip_req *)nlmsg;
ip_req->nlmsg.nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
ip_req->nlmsg.nlmsghdr.nlmsg_len =
NLMSG_LENGTH(sizeof(struct ifaddrmsg));
ip_req->nlmsg.nlmsghdr.nlmsg_flags =
NLM_F_ACK|NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL;
ip_req->nlmsg.nlmsghdr.nlmsg_type = RTM_NEWADDR;
@ -740,10 +742,13 @@ int lxc_ip_addr_add(int family, int ifindex, void *addr, int prefix)
if (nla_put_buffer(nlmsg, IFA_ADDRESS, addr, addrlen))
goto out;
/* if (in_bcast.s_addr != INADDR_ANY) */
/* if (nla_put_buffer(nlmsg, IFA_BROADCAST, &in_bcast, */
/* sizeof(in_bcast))) */
/* goto out; */
if (bcast && nla_put_buffer(nlmsg, IFA_BROADCAST, bcast, addrlen))
goto out;
/* TODO : multicast, anycast with ipv6 */
err = EPROTONOSUPPORT;
if ((bcast || acast) && family == AF_INET6)
goto out;
err = netlink_transaction(&nlh, nlmsg, answer);
out:
@ -753,6 +758,19 @@ out:
return err;
}
int lxc_ipv6_addr_add(int ifindex, struct in6_addr *addr,
struct in6_addr *mcast,
struct in6_addr *acast, int prefix)
{
return ip_addr_add(AF_INET6, ifindex, addr, mcast, acast, prefix);
}
int lxc_ipv4_addr_add(int ifindex, struct in_addr *addr,
struct in_addr *bcast, int prefix)
{
return ip_addr_add(AF_INET, ifindex, addr, bcast, NULL, prefix);
}
/*
* There is a lxc_bridge_attach, but no need of a bridge detach
* as automatically done by kernel when device deleted.

View File

@ -91,7 +91,12 @@ extern int lxc_ip_forward_off(const char *name, int family);
/*
* Set ip address
*/
extern int lxc_ip_addr_add(int family, int ifindex, void *addr, int prefix);
extern int lxc_ipv6_addr_add(int ifindex, struct in6_addr *addr,
struct in6_addr *mcast,
struct in6_addr *acast, int prefix);
extern int lxc_ipv4_addr_add(int ifindex, struct in_addr *addr,
struct in_addr *bcast, int prefix);
/*
* Attach an interface to the bridge