Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
4bf1968d
Commit
4bf1968d
authored
Oct 09, 2009
by
Daniel Lezcano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out some network code
We can factor out the "ip addr add" Signed-off-by:
Daniel Lezcano
<
dlezcano@fr.ibm.com
>
parent
82d5ae15
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
68 deletions
+15
-68
conf.c
src/lxc/conf.c
+5
-6
network.c
src/lxc/network.c
+9
-57
network.h
src/lxc/network.h
+1
-5
No files found.
src/lxc/conf.c
View file @
4bf1968d
...
@@ -787,8 +787,8 @@ static int setup_ipv4_addr(struct lxc_list *ip, int ifindex)
...
@@ -787,8 +787,8 @@ static int setup_ipv4_addr(struct lxc_list *ip, int ifindex)
inetdev
=
iterator
->
elem
;
inetdev
=
iterator
->
elem
;
if
(
lxc_ip_addr_add
(
ifindex
,
inetdev
->
addr
,
if
(
lxc_ip_addr_add
(
AF_INET
,
ifindex
,
inetdev
->
prefix
,
inetdev
->
bcast
))
{
&
inetdev
->
addr
,
inetdev
->
prefix
))
{
return
-
1
;
return
-
1
;
}
}
}
}
...
@@ -799,16 +799,15 @@ static int setup_ipv4_addr(struct lxc_list *ip, int ifindex)
...
@@ -799,16 +799,15 @@ static int setup_ipv4_addr(struct lxc_list *ip, int ifindex)
static
int
setup_ipv6_addr
(
struct
lxc_list
*
ip
,
int
ifindex
)
static
int
setup_ipv6_addr
(
struct
lxc_list
*
ip
,
int
ifindex
)
{
{
struct
lxc_list
*
iterator
;
struct
lxc_list
*
iterator
;
struct
lxc_inet
6
dev
*
inet6dev
;
struct
lxc_inetdev
*
inet6dev
;
lxc_list_for_each
(
iterator
,
ip
)
{
lxc_list_for_each
(
iterator
,
ip
)
{
inet6dev
=
iterator
->
elem
;
inet6dev
=
iterator
->
elem
;
if
(
lxc_ip
6_addr_add
(
ifindex
,
inet6dev
->
addr
,
if
(
lxc_ip
_addr_add
(
AF_INET6
,
ifindex
,
inet6dev
->
prefix
,
inet6dev
->
bcast
))
{
&
inet6dev
->
addr
,
inet6dev
->
prefix
))
return
-
1
;
return
-
1
;
}
}
}
return
0
;
return
0
;
...
...
src/lxc/network.c
View file @
4bf1968d
...
@@ -86,7 +86,7 @@ int lxc_device_move(int ifindex, pid_t pid)
...
@@ -86,7 +86,7 @@ int lxc_device_move(int ifindex, pid_t pid)
struct
nl_handler
nlh
;
struct
nl_handler
nlh
;
struct
nlmsg
*
nlmsg
=
NULL
;
struct
nlmsg
*
nlmsg
=
NULL
;
struct
link_req
*
link_req
;
struct
link_req
*
link_req
;
int
len
,
err
=
-
1
;
int
err
=
-
1
;
if
(
netlink_open
(
&
nlh
,
NETLINK_ROUTE
))
if
(
netlink_open
(
&
nlh
,
NETLINK_ROUTE
))
return
-
1
;
return
-
1
;
...
@@ -565,14 +565,17 @@ int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr)
...
@@ -565,14 +565,17 @@ int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr)
return
0
;
return
0
;
}
}
int
lxc_ip_addr_add
(
int
ifindex
,
struct
in_addr
in_addr
,
int
lxc_ip_addr_add
(
int
family
,
int
ifindex
,
void
*
addr
,
int
prefix
)
int
prefix
,
struct
in_addr
in_bcast
)
{
{
struct
nl_handler
nlh
;
struct
nl_handler
nlh
;
struct
nlmsg
*
nlmsg
=
NULL
,
*
answer
=
NULL
;
struct
nlmsg
*
nlmsg
=
NULL
,
*
answer
=
NULL
;
struct
ip_req
*
ip_req
;
struct
ip_req
*
ip_req
;
int
addrlen
;
int
err
=
-
1
;
int
err
=
-
1
;
addrlen
=
family
==
AF_INET
?
sizeof
(
struct
in_addr
)
:
sizeof
(
struct
in6_addr
);
if
(
netlink_open
(
&
nlh
,
NETLINK_ROUTE
))
if
(
netlink_open
(
&
nlh
,
NETLINK_ROUTE
))
return
-
1
;
return
-
1
;
...
@@ -591,13 +594,13 @@ int lxc_ip_addr_add(int ifindex, struct in_addr in_addr,
...
@@ -591,13 +594,13 @@ int lxc_ip_addr_add(int ifindex, struct in_addr in_addr,
ip_req
->
nlmsg
.
nlmsghdr
.
nlmsg_type
=
RTM_NEWADDR
;
ip_req
->
nlmsg
.
nlmsghdr
.
nlmsg_type
=
RTM_NEWADDR
;
ip_req
->
ifa
.
ifa_prefixlen
=
prefix
;
ip_req
->
ifa
.
ifa_prefixlen
=
prefix
;
ip_req
->
ifa
.
ifa_index
=
ifindex
;
ip_req
->
ifa
.
ifa_index
=
ifindex
;
ip_req
->
ifa
.
ifa_family
=
AF_INET
;
ip_req
->
ifa
.
ifa_family
=
family
;
ip_req
->
ifa
.
ifa_scope
=
0
;
ip_req
->
ifa
.
ifa_scope
=
0
;
if
(
nla_put_buffer
(
nlmsg
,
IFA_LOCAL
,
&
in_addr
,
sizeof
(
in_addr
)
))
if
(
nla_put_buffer
(
nlmsg
,
IFA_LOCAL
,
addr
,
addrlen
))
goto
out
;
goto
out
;
if
(
nla_put_buffer
(
nlmsg
,
IFA_ADDRESS
,
&
in_addr
,
sizeof
(
in_addr
)
))
if
(
nla_put_buffer
(
nlmsg
,
IFA_ADDRESS
,
addr
,
addrlen
))
goto
out
;
goto
out
;
/* if (in_bcast.s_addr != INADDR_ANY) */
/* if (in_bcast.s_addr != INADDR_ANY) */
...
@@ -616,57 +619,6 @@ out:
...
@@ -616,57 +619,6 @@ out:
return
err
;
return
err
;
}
}
int
lxc_ip6_addr_add
(
int
ifindex
,
struct
in6_addr
in6_addr
,
int
prefix
,
struct
in6_addr
in6_bcast
)
{
struct
nl_handler
nlh
;
struct
nlmsg
*
nlmsg
=
NULL
,
*
answer
=
NULL
;
struct
ip_req
*
ip_req
;
int
err
=
-
1
;
if
(
netlink_open
(
&
nlh
,
NETLINK_ROUTE
))
return
-
1
;
nlmsg
=
nlmsg_alloc
(
NLMSG_GOOD_SIZE
);
if
(
!
nlmsg
)
goto
out
;
answer
=
nlmsg_alloc
(
NLMSG_GOOD_SIZE
);
if
(
!
answer
)
goto
out
;
ip_req
=
(
struct
ip_req
*
)
nlmsg
;
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
;
ip_req
->
ifa
.
ifa_prefixlen
=
prefix
;
ip_req
->
ifa
.
ifa_index
=
ifindex
;
ip_req
->
ifa
.
ifa_family
=
AF_INET6
;
ip_req
->
ifa
.
ifa_scope
=
0
;
if
(
nla_put_buffer
(
nlmsg
,
IFA_LOCAL
,
&
in6_addr
,
sizeof
(
in6_addr
)))
goto
out
;
if
(
nla_put_buffer
(
nlmsg
,
IFA_ADDRESS
,
&
in6_addr
,
sizeof
(
in6_addr
)))
goto
out
;
/* if (in6_bcast.s6_addr != in6addr_any.s6_addr) */
/* if (nla_put_buffer(nlmsg, IFA_BROADCAST, &in6_bcast, */
/* sizeof(in6_bcast))) */
/* goto out; */
if
(
netlink_transaction
(
&
nlh
,
nlmsg
,
answer
))
goto
out
;
err
=
0
;
out:
netlink_close
(
&
nlh
);
nlmsg_free
(
answer
);
nlmsg_free
(
nlmsg
);
return
err
;
}
static
int
bridge_add_del_interface
(
const
char
*
bridge
,
static
int
bridge_add_del_interface
(
const
char
*
bridge
,
const
char
*
ifname
,
int
detach
)
const
char
*
ifname
,
int
detach
)
{
{
...
...
src/lxc/network.h
View file @
4bf1968d
...
@@ -81,11 +81,7 @@ extern int lxc_ip_forward_off(const char *name, int family);
...
@@ -81,11 +81,7 @@ extern int lxc_ip_forward_off(const char *name, int family);
/*
/*
* Set ip address
* Set ip address
*/
*/
extern
int
lxc_ip_addr_add
(
int
ifindex
,
struct
in_addr
addr
,
extern
int
lxc_ip_addr_add
(
int
family
,
int
ifindex
,
void
*
addr
,
int
prefix
);
int
prefix
,
struct
in_addr
bcast
);
extern
int
lxc_ip6_addr_add
(
int
ifindex
,
struct
in6_addr
addr
,
int
prefix
,
struct
in6_addr
bcast
);
/*
/*
* Attach an interface to the bridge
* Attach an interface to the bridge
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment