81
81
struct ifaddrmsg ifa;
84
int lxc_device_move(const char *name, pid_t pid)
84
int lxc_device_move(int ifindex, pid_t pid)
86
86
struct nl_handler nlh;
87
87
struct nlmsg *nlmsg = NULL;
88
88
struct link_req *link_req;
89
int index, len, err = -1;
91
91
if (netlink_open(&nlh, NETLINK_ROUTE))
95
if (len == 1 || len > IFNAMSIZ)
98
94
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
102
index = if_nametoindex(name);
106
98
link_req = (struct link_req *)nlmsg;
107
99
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
108
link_req->ifinfomsg.ifi_index = index;
100
link_req->ifinfomsg.ifi_index = ifindex;
109
101
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
110
102
nlmsg->nlmsghdr.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
111
103
nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
113
105
if (nla_put_u32(nlmsg, IFLA_NET_NS_PID, pid))
116
if (nla_put_string(nlmsg, IFLA_IFNAME, name))
119
108
if (netlink_transaction(&nlh, nlmsg, nlmsg))
579
int lxc_ip_addr_add(const char *ifname, const char *addr,
580
int prefix, const char *bcast)
568
int lxc_ip_addr_add(int family, int ifindex, void *addr, int prefix)
582
570
struct nl_handler nlh;
583
struct in_addr in_addr;
584
/* struct in_addr in_bcast; */
585
571
struct nlmsg *nlmsg = NULL, *answer = NULL;
586
572
struct ip_req *ip_req;
587
int ifindex, err = -1;
576
addrlen = family == AF_INET ? sizeof(struct in_addr) :
577
sizeof(struct in6_addr);
589
579
if (netlink_open(&nlh, NETLINK_ROUTE))
592
if (inet_pton(AF_INET, addr, (void *)&in_addr) < 0)
595
/* if (inet_pton(AF_INET, bcast, (void *)&in_bcast) < 0) */
598
582
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
614
594
ip_req->nlmsg.nlmsghdr.nlmsg_type = RTM_NEWADDR;
615
595
ip_req->ifa.ifa_prefixlen = prefix;
616
596
ip_req->ifa.ifa_index = ifindex;
617
ip_req->ifa.ifa_family = AF_INET;
597
ip_req->ifa.ifa_family = family;
618
598
ip_req->ifa.ifa_scope = 0;
620
if (nla_put_buffer(nlmsg, IFA_LOCAL, &in_addr, sizeof(in_addr)))
600
if (nla_put_buffer(nlmsg, IFA_LOCAL, addr, addrlen))
623
if (nla_put_buffer(nlmsg, IFA_ADDRESS, &in_addr, sizeof(in_addr)))
603
if (nla_put_buffer(nlmsg, IFA_ADDRESS, addr, addrlen))
626
606
/* if (in_bcast.s_addr != INADDR_ANY) */
642
int lxc_ip6_addr_add(const char *ifname, const char *addr,
643
int prefix, const char *bcast)
645
struct nl_handler nlh;
646
struct in6_addr in6_addr;
647
/* struct in6_addr in6_bcast; */
648
struct nlmsg *nlmsg = NULL, *answer = NULL;
649
struct ip_req *ip_req;
650
int ifindex, err = -1;
652
if (netlink_open(&nlh, NETLINK_ROUTE))
655
if (inet_pton(AF_INET6, addr, (void *)&in6_addr) < 0)
659
/* if (inet_pton(AF_INET6, bcast, (void *)&in6_bcast) < 0) */
662
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
666
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
670
ifindex = if_nametoindex(ifname);
674
ip_req = (struct ip_req *)nlmsg;
675
ip_req->nlmsg.nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
676
ip_req->nlmsg.nlmsghdr.nlmsg_flags =
677
NLM_F_ACK|NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL;
678
ip_req->nlmsg.nlmsghdr.nlmsg_type = RTM_NEWADDR;
679
ip_req->ifa.ifa_prefixlen = prefix;
680
ip_req->ifa.ifa_index = ifindex;
681
ip_req->ifa.ifa_family = AF_INET6;
682
ip_req->ifa.ifa_scope = 0;
684
if (nla_put_buffer(nlmsg, IFA_LOCAL, &in6_addr, sizeof(in6_addr)))
687
if (nla_put_buffer(nlmsg, IFA_ADDRESS, &in6_addr, sizeof(in6_addr)))
690
/* if (in6_bcast.s6_addr != in6addr_any.s6_addr) */
691
/* if (nla_put_buffer(nlmsg, IFA_BROADCAST, &in6_bcast, */
692
/* sizeof(in6_bcast))) */
695
if (netlink_transaction(&nlh, nlmsg, answer))
706
622
static int bridge_add_del_interface(const char *bridge,
707
623
const char *ifname, int detach)