mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-08 20:35:42 +00:00
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:
parent
9232212afd
commit
1f1b18e754
@ -699,7 +699,8 @@ int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr)
|
|||||||
return 0;
|
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 nl_handler nlh;
|
||||||
struct nlmsg *nlmsg = NULL, *answer = NULL;
|
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;
|
goto out;
|
||||||
|
|
||||||
ip_req = (struct ip_req *)nlmsg;
|
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 =
|
ip_req->nlmsg.nlmsghdr.nlmsg_flags =
|
||||||
NLM_F_ACK|NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL;
|
NLM_F_ACK|NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL;
|
||||||
ip_req->nlmsg.nlmsghdr.nlmsg_type = RTM_NEWADDR;
|
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))
|
if (nla_put_buffer(nlmsg, IFA_ADDRESS, addr, addrlen))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* if (in_bcast.s_addr != INADDR_ANY) */
|
if (bcast && nla_put_buffer(nlmsg, IFA_BROADCAST, bcast, addrlen))
|
||||||
/* if (nla_put_buffer(nlmsg, IFA_BROADCAST, &in_bcast, */
|
goto out;
|
||||||
/* sizeof(in_bcast))) */
|
|
||||||
/* goto out; */
|
/* TODO : multicast, anycast with ipv6 */
|
||||||
|
err = EPROTONOSUPPORT;
|
||||||
|
if ((bcast || acast) && family == AF_INET6)
|
||||||
|
goto out;
|
||||||
|
|
||||||
err = netlink_transaction(&nlh, nlmsg, answer);
|
err = netlink_transaction(&nlh, nlmsg, answer);
|
||||||
out:
|
out:
|
||||||
@ -753,6 +758,19 @@ out:
|
|||||||
return err;
|
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
|
* There is a lxc_bridge_attach, but no need of a bridge detach
|
||||||
* as automatically done by kernel when device deleted.
|
* as automatically done by kernel when device deleted.
|
||||||
|
@ -91,7 +91,12 @@ extern int lxc_ip_forward_off(const char *name, int family);
|
|||||||
/*
|
/*
|
||||||
* Set ip address
|
* 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
|
* Attach an interface to the bridge
|
||||||
|
Loading…
Reference in New Issue
Block a user