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
3392d379
Unverified
Commit
3392d379
authored
Feb 26, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
network: add lxc_network_info struct
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
4a037d61
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
60 deletions
+63
-60
network.c
src/lxc/network.c
+63
-60
No files found.
src/lxc/network.c
View file @
3392d379
...
@@ -50,6 +50,69 @@ typedef int (*netdev_configure_server_cb)(struct lxc_handler *, struct lxc_netde
...
@@ -50,6 +50,69 @@ typedef int (*netdev_configure_server_cb)(struct lxc_handler *, struct lxc_netde
typedef
int
(
*
netdev_configure_container_cb
)(
struct
lxc_netdev
*
);
typedef
int
(
*
netdev_configure_container_cb
)(
struct
lxc_netdev
*
);
typedef
int
(
*
netdev_shutdown_server_cb
)(
struct
lxc_handler
*
,
struct
lxc_netdev
*
);
typedef
int
(
*
netdev_shutdown_server_cb
)(
struct
lxc_handler
*
,
struct
lxc_netdev
*
);
const
struct
lxc_network_info
{
const
char
*
name
;
const
char
*
template
;
}
lxc_network_info
[
LXC_NET_MAXCONFTYPE
+
1
]
=
{
[
LXC_NET_EMPTY
]
=
{
"empty"
,
"emptXXXXXX"
},
[
LXC_NET_VETH
]
=
{
"veth"
,
"vethXXXXXX"
},
[
LXC_NET_MACVLAN
]
=
{
"macvlan"
,
"macvXXXXXX"
},
[
LXC_NET_IPVLAN
]
=
{
"ipvlan"
,
"ipvlXXXXXX"
},
[
LXC_NET_PHYS
]
=
{
"phys"
,
"physXXXXXX"
},
[
LXC_NET_VLAN
]
=
{
"vlan"
,
"vlanXXXXXX"
},
[
LXC_NET_NONE
]
=
{
"none"
,
"noneXXXXXX"
},
[
LXC_NET_MAXCONFTYPE
]
=
{
NULL
,
NULL
}
};
const
char
*
lxc_net_type_to_str
(
int
type
)
{
if
(
type
<
0
||
type
>
LXC_NET_MAXCONFTYPE
)
return
NULL
;
return
lxc_network_info
[
type
].
name
;
}
static
const
char
padchar
[]
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
char
*
lxc_ifname_alnum_case_sensitive
(
char
*
template
)
{
char
name
[
IFNAMSIZ
];
size_t
i
=
0
;
#ifdef HAVE_RAND_R
unsigned
int
seed
;
seed
=
randseed
(
false
);
#else
(
void
)
randseed
(
true
);
#endif
if
(
strlen
(
template
)
>=
IFNAMSIZ
)
return
NULL
;
/* Generate random names until we find one that doesn't exist. */
for
(;;)
{
name
[
0
]
=
'\0'
;
(
void
)
strlcpy
(
name
,
template
,
IFNAMSIZ
);
for
(
i
=
0
;
i
<
strlen
(
name
);
i
++
)
{
if
(
name
[
i
]
==
'X'
)
{
#ifdef HAVE_RAND_R
name
[
i
]
=
padchar
[
rand_r
(
&
seed
)
%
strlen
(
padchar
)];
#else
name
[
i
]
=
padchar
[
rand
()
%
strlen
(
padchar
)];
#endif
}
}
if
(
if_nametoindex
(
name
)
==
0
)
break
;
}
(
void
)
strlcpy
(
template
,
name
,
strlen
(
template
)
+
1
);
return
template
;
}
static
const
char
loop_device
[]
=
"lo"
;
static
const
char
loop_device
[]
=
"lo"
;
static
int
lxc_ip_route_dest
(
__u16
nlmsg_type
,
int
family
,
int
ifindex
,
void
*
dest
,
unsigned
int
netmask
)
static
int
lxc_ip_route_dest
(
__u16
nlmsg_type
,
int
family
,
int
ifindex
,
void
*
dest
,
unsigned
int
netmask
)
...
@@ -2736,66 +2799,6 @@ int lxc_bridge_attach(const char *bridge, const char *ifname)
...
@@ -2736,66 +2799,6 @@ int lxc_bridge_attach(const char *bridge, const char *ifname)
return
err
;
return
err
;
}
}
static
const
char
*
const
lxc_network_types
[
LXC_NET_MAXCONFTYPE
+
1
]
=
{
[
LXC_NET_EMPTY
]
=
"empty"
,
[
LXC_NET_VETH
]
=
"veth"
,
[
LXC_NET_MACVLAN
]
=
"macvlan"
,
[
LXC_NET_IPVLAN
]
=
"ipvlan"
,
[
LXC_NET_PHYS
]
=
"phys"
,
[
LXC_NET_VLAN
]
=
"vlan"
,
[
LXC_NET_NONE
]
=
"none"
,
};
const
char
*
lxc_net_type_to_str
(
int
type
)
{
if
(
type
<
0
||
type
>
LXC_NET_MAXCONFTYPE
)
return
NULL
;
return
lxc_network_types
[
type
];
}
static
const
char
padchar
[]
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
char
*
lxc_ifname_alnum_case_sensitive
(
char
*
template
)
{
char
name
[
IFNAMSIZ
];
size_t
i
=
0
;
#ifdef HAVE_RAND_R
unsigned
int
seed
;
seed
=
randseed
(
false
);
#else
(
void
)
randseed
(
true
);
#endif
if
(
strlen
(
template
)
>=
IFNAMSIZ
)
return
NULL
;
/* Generate random names until we find one that doesn't exist. */
for
(;;)
{
name
[
0
]
=
'\0'
;
(
void
)
strlcpy
(
name
,
template
,
IFNAMSIZ
);
for
(
i
=
0
;
i
<
strlen
(
name
);
i
++
)
{
if
(
name
[
i
]
==
'X'
)
{
#ifdef HAVE_RAND_R
name
[
i
]
=
padchar
[
rand_r
(
&
seed
)
%
strlen
(
padchar
)];
#else
name
[
i
]
=
padchar
[
rand
()
%
strlen
(
padchar
)];
#endif
}
}
if
(
if_nametoindex
(
name
)
==
0
)
break
;
}
(
void
)
strlcpy
(
template
,
name
,
strlen
(
template
)
+
1
);
return
template
;
}
int
setup_private_host_hw_addr
(
char
*
veth1
)
int
setup_private_host_hw_addr
(
char
*
veth1
)
{
{
__do_close
int
sockfd
=
-
EBADF
;
__do_close
int
sockfd
=
-
EBADF
;
...
...
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