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
edfb9a57
Commit
edfb9a57
authored
Mar 07, 2011
by
Daniel Lezcano
Committed by
Daniel Lezcano
Mar 07, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
factor out networking configuration code
Change the name of the functions and factor some of them. Signed-off-by:
Daniel Lezcano
<
dlezcano@fr.ibm.com
>
parent
daa5d3fd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
84 deletions
+49
-84
conf.c
src/lxc/conf.c
+5
-5
network.c
src/lxc/network.c
+39
-71
network.h
src/lxc/network.h
+5
-8
No files found.
src/lxc/conf.c
View file @
edfb9a57
...
...
@@ -1241,7 +1241,7 @@ static int setup_netdev(struct lxc_netdev *netdev)
netdev
->
link
:
"eth%d"
;
/* rename the interface name */
err
=
lxc_
device_re
name
(
ifname
,
netdev
->
name
);
err
=
lxc_
netdev_rename_by_
name
(
ifname
,
netdev
->
name
);
if
(
err
)
{
ERROR
(
"failed to rename %s->%s : %s"
,
ifname
,
netdev
->
name
,
strerror
(
-
err
));
...
...
@@ -1425,7 +1425,7 @@ static int instanciate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
return
0
;
out_delete:
lxc_
device_delet
e
(
veth1
);
lxc_
netdev_delete_by_nam
e
(
veth1
);
return
-
1
;
}
...
...
@@ -1458,7 +1458,7 @@ static int instanciate_macvlan(struct lxc_handler *handler, struct lxc_netdev *n
netdev
->
ifindex
=
if_nametoindex
(
peer
);
if
(
!
netdev
->
ifindex
)
{
ERROR
(
"failed to retrieve the index for %s"
,
peer
);
lxc_
device_delet
e
(
peer
);
lxc_
netdev_delete_by_nam
e
(
peer
);
return
-
1
;
}
...
...
@@ -1498,7 +1498,7 @@ static int instanciate_vlan(struct lxc_handler *handler, struct lxc_netdev *netd
netdev
->
ifindex
=
if_nametoindex
(
peer
);
if
(
!
netdev
->
ifindex
)
{
ERROR
(
"failed to retrieve the ifindex for %s"
,
peer
);
lxc_
device_delet
e
(
peer
);
lxc_
netdev_delete_by_nam
e
(
peer
);
return
-
1
;
}
...
...
@@ -1579,7 +1579,7 @@ void lxc_delete_network(struct lxc_list *network)
lxc_list_for_each
(
iterator
,
network
)
{
netdev
=
iterator
->
elem
;
if
(
netdev
->
ifindex
>
0
&&
netdev
->
type
!=
LXC_NET_PHYS
)
lxc_
device_delete
_index
(
netdev
->
ifindex
);
lxc_
netdev_delete_by
_index
(
netdev
->
ifindex
);
}
}
...
...
src/lxc/network.c
View file @
edfb9a57
...
...
@@ -122,22 +122,17 @@ out:
return
err
;
}
int
lxc_
device_delete
(
const
char
*
name
)
int
lxc_
netdev_delete_by_index
(
int
ifindex
)
{
struct
nl_handler
nlh
;
struct
nlmsg
*
nlmsg
=
NULL
,
*
answer
=
NULL
;
struct
link_req
*
link_req
;
int
index
,
len
,
err
;
int
err
;
err
=
netlink_open
(
&
nlh
,
NETLINK_ROUTE
);
if
(
err
)
return
err
;
err
=
-
EINVAL
;
len
=
strlen
(
name
);
if
(
len
==
1
||
len
>
IFNAMSIZ
)
goto
out
;
err
=
-
ENOMEM
;
nlmsg
=
nlmsg_alloc
(
NLMSG_GOOD_SIZE
);
if
(
!
nlmsg
)
...
...
@@ -147,21 +142,13 @@ int lxc_device_delete(const char *name)
if
(
!
answer
)
goto
out
;
err
=
-
EINVAL
;
index
=
if_nametoindex
(
name
);
if
(
!
index
)
goto
out
;
link_req
=
(
struct
link_req
*
)
nlmsg
;
link_req
->
ifinfomsg
.
ifi_family
=
AF_UNSPEC
;
link_req
->
ifinfomsg
.
ifi_index
=
index
;
link_req
->
ifinfomsg
.
ifi_index
=
i
fi
ndex
;
nlmsg
->
nlmsghdr
.
nlmsg_len
=
NLMSG_LENGTH
(
sizeof
(
struct
ifinfomsg
));
nlmsg
->
nlmsghdr
.
nlmsg_flags
=
NLM_F_ACK
|
NLM_F_REQUEST
;
nlmsg
->
nlmsghdr
.
nlmsg_type
=
RTM_DELLINK
;
if
(
nla_put_string
(
nlmsg
,
IFLA_IFNAME
,
name
))
goto
out
;
err
=
netlink_transaction
(
&
nlh
,
nlmsg
,
answer
);
out:
netlink_close
(
&
nlh
);
...
...
@@ -170,17 +157,32 @@ out:
return
err
;
}
int
lxc_device_delete_index
(
int
ifindex
)
int
lxc_netdev_delete_by_name
(
const
char
*
name
)
{
int
index
;
index
=
if_nametoindex
(
name
);
if
(
!
index
)
return
-
EINVAL
;
return
lxc_netdev_delete_by_index
(
index
);
}
int
lxc_netdev_rename_by_index
(
int
ifindex
,
const
char
*
newname
)
{
struct
nl_handler
nlh
;
struct
nlmsg
*
nlmsg
=
NULL
,
*
answer
=
NULL
;
struct
link_req
*
link_req
;
int
err
;
int
len
,
err
;
err
=
netlink_open
(
&
nlh
,
NETLINK_ROUTE
);
if
(
err
)
return
err
;
len
=
strlen
(
newname
);
if
(
len
==
1
||
len
>
IFNAMSIZ
)
goto
out
;
err
=
-
ENOMEM
;
nlmsg
=
nlmsg_alloc
(
NLMSG_GOOD_SIZE
);
if
(
!
nlmsg
)
...
...
@@ -195,7 +197,10 @@ int lxc_device_delete_index(int ifindex)
link_req
->
ifinfomsg
.
ifi_index
=
ifindex
;
nlmsg
->
nlmsghdr
.
nlmsg_len
=
NLMSG_LENGTH
(
sizeof
(
struct
ifinfomsg
));
nlmsg
->
nlmsghdr
.
nlmsg_flags
=
NLM_F_ACK
|
NLM_F_REQUEST
;
nlmsg
->
nlmsghdr
.
nlmsg_type
=
RTM_DELLINK
;
nlmsg
->
nlmsghdr
.
nlmsg_type
=
RTM_NEWLINK
;
if
(
nla_put_string
(
nlmsg
,
IFLA_IFNAME
,
newname
))
goto
out
;
err
=
netlink_transaction
(
&
nlh
,
nlmsg
,
answer
);
out:
...
...
@@ -205,6 +210,21 @@ out:
return
err
;
}
int
lxc_netdev_rename_by_name
(
const
char
*
oldname
,
const
char
*
newname
)
{
int
len
,
index
;
len
=
strlen
(
oldname
);
if
(
len
==
1
||
len
>
IFNAMSIZ
)
return
-
EINVAL
;
index
=
if_nametoindex
(
oldname
);
if
(
!
index
)
return
-
EINVAL
;
return
lxc_netdev_rename_by_index
(
index
,
newname
);
}
static
int
device_set_flag
(
const
char
*
name
,
int
flag
)
{
struct
nl_handler
nlh
;
...
...
@@ -310,58 +330,6 @@ int lxc_device_down(const char *name)
return
device_set_flag
(
name
,
0
);
}
int
lxc_device_rename
(
const
char
*
oldname
,
const
char
*
newname
)
{
struct
nl_handler
nlh
;
struct
nlmsg
*
nlmsg
=
NULL
,
*
answer
=
NULL
;
struct
link_req
*
link_req
;
int
index
,
len
,
err
;
err
=
netlink_open
(
&
nlh
,
NETLINK_ROUTE
);
if
(
err
)
return
err
;
err
=
-
EINVAL
;
len
=
strlen
(
oldname
);
if
(
len
==
1
||
len
>
IFNAMSIZ
)
goto
out
;
len
=
strlen
(
newname
);
if
(
len
==
1
||
len
>
IFNAMSIZ
)
goto
out
;
err
=
-
ENOMEM
;
nlmsg
=
nlmsg_alloc
(
NLMSG_GOOD_SIZE
);
if
(
!
nlmsg
)
goto
out
;
answer
=
nlmsg_alloc
(
NLMSG_GOOD_SIZE
);
if
(
!
answer
)
goto
out
;
err
=
-
EINVAL
;
index
=
if_nametoindex
(
oldname
);
if
(
!
index
)
goto
out
;
link_req
=
(
struct
link_req
*
)
nlmsg
;
link_req
->
ifinfomsg
.
ifi_family
=
AF_UNSPEC
;
link_req
->
ifinfomsg
.
ifi_index
=
index
;
nlmsg
->
nlmsghdr
.
nlmsg_len
=
NLMSG_LENGTH
(
sizeof
(
struct
ifinfomsg
));
nlmsg
->
nlmsghdr
.
nlmsg_flags
=
NLM_F_ACK
|
NLM_F_REQUEST
;
nlmsg
->
nlmsghdr
.
nlmsg_type
=
RTM_NEWLINK
;
if
(
nla_put_string
(
nlmsg
,
IFLA_IFNAME
,
newname
))
goto
out
;
err
=
netlink_transaction
(
&
nlh
,
nlmsg
,
answer
);
out:
netlink_close
(
&
nlh
);
nlmsg_free
(
answer
);
nlmsg_free
(
nlmsg
);
return
err
;
}
int
lxc_veth_create
(
const
char
*
name1
,
const
char
*
name2
)
{
struct
nl_handler
nlh
;
...
...
src/lxc/network.h
View file @
edfb9a57
...
...
@@ -36,12 +36,14 @@ extern int lxc_device_move(int ifindex, pid_t pid);
/*
* Delete a network device
*/
extern
int
lxc_device_delete
(
const
char
*
name
);
extern
int
lxc_netdev_delete_by_name
(
const
char
*
name
);
extern
int
lxc_netdev_delete_by_index
(
int
ifindex
);
/*
*
Delete a network device by the index
*
Change the device name
*/
extern
int
lxc_device_delete_index
(
int
ifindex
);
extern
int
lxc_netdev_rename_by_name
(
const
char
*
oldname
,
const
char
*
newname
);
extern
int
lxc_netdev_rename_by_index
(
int
ifindex
,
const
char
*
newname
);
/*
* Set the device network up
...
...
@@ -54,11 +56,6 @@ extern int lxc_device_up(const char *name);
extern
int
lxc_device_down
(
const
char
*
name
);
/*
* Change the device name
*/
extern
int
lxc_device_rename
(
const
char
*
oldname
,
const
char
*
newname
);
/*
* Change the mtu size for the specified device
*/
extern
int
lxc_device_set_mtu
(
const
char
*
name
,
int
mtu
);
...
...
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