Virtual network¶
-
group
network
Functions, and related data types, for manipulating network objects and their settings.
Virtual network is a collection of virts that can communicate with each other as if they were on the same LAN. At the same time, they are isolated from other virtual networks, as well as from the host network. Distinct virtual networks can have hosts with same MAC addresses, and it is impossible to read packets belonging to other networks (or the host network), or send packets that travel outside the virtual network.
The lsdn_net object represents a network in the sense of “collection of virts”. Apart from basic life-cycle and lookup functions, it is only possible to add or remove virts to/from it.
Configuration of network properties is done through separate lsdn_settings objects. There is a
lsdn_<kind>_settings_new
function for each kind of network encapsulation, with different required parameters. It is also possible to register user hooks for startup and shutdown events.An exception to this is the
vnet_id
property, which is set on a network directly, as opposed to being a part of settings. It configures the VNET (or encapsulation ID) of the network. That means that several networks can share a common settings object while still being differentiated byvnet_id
.Network object management
-
struct lsdn_net*
lsdn_net_new
(struct lsdn_settings * settings, uint32_t vnet_id)¶ Create a new network.
Creates a virtual network object with id
vnet_id
, configured bys
.Multiple networks can share the same lsdn_settings, as long as they differ by
vnet_id
.- Return
- newly allocated lsdn_net structure.
-
struct lsdn_net*
lsdn_net_by_name
(struct lsdn_context * ctx, const char * name)¶ Find a network by name.
- Return
- lsdn_net structure if a network with this name exists.
- Return
NULL
otherwise.
Network settings
-
struct lsdn_settings*
lsdn_settings_new_direct
(struct lsdn_context * ctx)¶ Create settings for a new direct network.
- Return
- new lsdn_settings instance.
- Parameters
ctx
: LSDN context.
-
struct lsdn_settings*
lsdn_settings_new_vlan
(struct lsdn_context * ctx)¶ Create settings for a new VLAN network.
- Return
- new lsdn_settings instance.
- Parameters
ctx
: LSDN context.
-
struct lsdn_settings*
lsdn_settings_new_vxlan_mcast
(struct lsdn_context * ctx, lsdn_ip_t mcast_ip, uint16_t port)¶ Create settings for a new VXLAN-multicast network.
- Return
- new lsdn_settings instance.
- Parameters
ctx
: LSDN context.mcast_ip
: Multicast group IP address.port
: UDP port for VXLAN tunnel.
-
struct lsdn_settings*
lsdn_settings_new_vxlan_e2e
(struct lsdn_context * ctx, uint16_t port)¶ Create settings for a new VXLAN-e2e network.
- Return
- new lsdn_settings instance.
- Parameters
ctx
: LSDN context.port
: UDP port for VXLAN tunnel.
-
struct lsdn_settings*
lsdn_settings_new_vxlan_static
(struct lsdn_context * ctx, uint16_t port)¶ Create settings for a new VXLAN-static network.
- Return
- new lsdn_settings instance.
- Parameters
ctx
: LSDN context.port
: UDP port for VXLAN tunnel.
-
struct lsdn_settings*
lsdn_settings_new_geneve
(struct lsdn_context * ctx, uint16_t port)¶ Create settings for a new GENEVE network.
- Return
- new lsdn_settings instance.
- Parameters
ctx
: LSDN context.port
: UDP port for GENEVE tunnel.
-
struct lsdn_settings*
lsdn_settings_new_geneve_e2e
(struct lsdn_context * ctx, uint16_t port)¶ Create settings for a new GENEVE network.
- Return
- new lsdn_settings instance.
- Parameters
ctx
: LSDN context.port
: UDP port for GENEVE tunnel.
-
void
lsdn_settings_free
(struct lsdn_settings * settings)¶ Free settings object.
Deletes the settings object and all lsdn_net objects that use it.
-
void
lsdn_settings_register_user_hooks
(struct lsdn_settings * settings, struct lsdn_user_hooks * user_hooks)¶ Configure user hooks.
Associates a lsdn_user_hooks structure with
settings
.
-
lsdn_err_t
lsdn_settings_set_name
(struct lsdn_settings * s, const char * name)¶ Assign a name to settings.
- Return Value
LSDNE_OK
: if the name is successfully set.LSDNE_DUPLICATE
: if this name is already in use.
-
const char*
lsdn_settings_get_name
(struct lsdn_settings * s)¶ Get settings name.
- Return
- name of the settings struct.
-
struct lsdn_settings*
lsdn_settings_by_name
(struct lsdn_context * ctx, const char * name)¶ Find settings by name.
Searches the context for a named lsdn_settings object and returns it.
- Return
- Pointer to lsdn_settings with this name.
- Return
NULL
if no settings with that name exist in the context.- Parameters
ctx
: LSDN context.name
: Requested name
Defines
-
lsdn_mk_net_name
(ctx)¶ Generate unique name for a net.
- See
- lsdn_mk_name
- Parameters
ctx
: LSDN context.
-
lsdn_mk_settings_name
(ctx)¶ Generate unique name for a settings object.
- See
- lsdn_mk_name
- Parameters
ctx
: LSDN context.
-
struct
lsdn_user_hooks
¶ - #include <lsdn.h>
User callback hooks.
Configured as part of lsdn_settings, this structure holds the callback hooks for startup and shutdown, and their custom data.
Public Members
-
void
(*lsdn_startup_hook)
(struct lsdn_net *net, struct lsdn_phys *phys, void *user)¶ Startup hook.
Called at commit time for every local phys and every network to which it is attached.
- Parameters
net
: network.phys
: attached phys.user
: receives the value of lsdn_startup_hook_user.
-
void*
lsdn_startup_hook_user
¶ Custom value for lsdn_startup_hook.
-
void*
lsdn_shutdown_hook_user
¶ Custom value for lsdn_shutdown_hook.
-
void
-
struct
lsdn_net
¶ - #include <lsdn.h>
Virtual network.
Network is a collection of virts that can communicate with each other.
See Virtual network.
See Phys (host machine).
-
struct
lsdn_settings
¶ - #include <lsdn.h>
Configuration structure for a virtual network.
Multiple networks can share the same settings (e.g. VXLAN with static routing on port 1234) and only differ by their identifier (VLAN id, VNI…).
See Virtual network.
-
struct lsdn_net*