Miscellaneous functions¶
-
group
misc
Miscellaneous functions and definitions.
This section documents the various odds and ends that didn’t fit anywhere else.
- String dump functions for converting the memory model to JSON or TCL representation
- Network-related definitions, such as frame lengths, header lengths, minimum and maximum IDs
- Network address types and enums
- Address initializer macros
- Address string parsing / dumping functions
- Address comparison functions
- Prefix validation functions
- Constants for broadcast addresses and full masks.
Dump to various formats
-
char*
lsdn_dump_context_json
(struct lsdn_context * ctx)¶ Dump the internal LSDN network model in JSON format.
- Return
- A C string containing the context’s representation in JSON format. Caller is responsible for deallocating the string using
free
.
-
char*
lsdn_dump_context_tcl
(struct lsdn_context * ctx)¶ Dump the internal LSDN network model in TCL format.
- Return
- A C string containing the context’s representation in lsctl-compatible form. Caller is responsible for deallocating the string using
free
.
Defines
-
lsdn_mk_iface_name
(ctx)¶ Generate unique name for an interface.
- See
- lsdn_mk_name
- Parameters
ctx
: LSDN context.
-
ETHERNET_FRAME_LEN
¶ Ethernet frame length in bytes.
-
IPv4_HEADER_LEN
¶ IPv4 header length in bytes.
-
IPv6_HEADER_LEN
¶ IPv6 header length in bytes.
-
UDP_HEADER_LEN
¶ UDP header length in bytes.
-
VXLAN_HEADER_LEN
¶ VXLAN header length in bytes.
-
GENEVE_HEADER_LEN
¶ GENEVE header length in bytes.
-
NET_GENEVE_MIN_VNET_ID
¶ Minimum allowed vnet id for GENEVE networks.
-
NET_GENEVE_MAX_VNET_ID
¶ Maximum allowed vnet id for GENEVE networks.
-
NET_VXLAN_MIN_VNET_ID
¶ Minimum allowed vnet id for VXLAN networks.
-
NET_VXLAN_MAX_VNET_ID
¶ Maximum allowed vnet id for VXLAN networks.
-
NET_VLAN_MIN_VNET_ID
¶ Minimum allowed vnet id for VLAN networks.
-
NET_VLAN_MAX_VNET_ID
¶ Maximum allowed vnet id for VLAN networks.
-
LSDN_MAC_LEN
¶ MAC address size in bytes.
-
LSDN_IPv4_LEN
¶ IPv4 address size in bytes.
-
LSDN_IPv6_LEN
¶ IPv6 address size in bytes.
-
LSDN_INITIALIZER_IPV4
(a, b, c, d)¶ struct literal for a lsdn_ip IPv4 address constructed from a 4-tuple.
-
LSDN_MK_IPV6
(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)¶ Construct a lsdn_ip IPv6 address from a 16-tuple.
-
LSDN_INITIALIZER_IPV6
(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)¶ struct literal for a lsdn_ip IPv6 address constructed from a 16-tuple.
-
LSDN_MK_MAC
(a, b, c, d, e, f)¶ Construct a lsdn_mac_t from a 6-tuple.
-
LSDN_INITIALIZER_MAC
(a, b, c, d, e, f)¶ struct literal for a lsdn_mac_t from a 6-tuple.
-
LSDN_MAC_STRING_LEN
¶ Maximum length of MAC address string.
Five colons, six hexadecimal octets.
-
LSDN_IPv4_STRING_LEN
¶ Maximum length of IPv4 address string.
Three dots, four decimal octets.
-
LSDN_IPv6_STRING_LEN
¶ Maximum length of IPv6 address string.
Seven colons, sixteen hexadecimal octets.
-
LSDN_IP_STRING_LEN
¶ Maximum length of address string for any IP address.
Typedefs
Functions
-
lsdn_err_t
lsdn_parse_mac
(lsdn_mac_t * mac, const char * ascii)¶ Parse MAC address string into lsdn_mac_t.
- Parameters
ascii
: MAC address string.mac
: parsed MAC address struct.
- Return Value
LSDNE_OK
: if parsed successfully.LSDNE_PARSE
: ifascii
could not be parsed into a MAC address.
-
bool
lsdn_mac_eq
(lsdn_mac_t a, lsdn_mac_t b)¶ Compare two lsdn_mac_t for equality.
- Return
true
ifa
andb
are equal,false
otherwise.- Parameters
a
: MAC address.b
: MAC address.
-
lsdn_err_t
lsdn_parse_ip
(lsdn_ip_t * ip, const char * ascii)¶ Parse IP address string into lsdn_ip_t.
- Parameters
ascii
: IP address string.ip
: parsed IP address struct.
- Return Value
LSDNE_OK
: if parsed successfully.LSDNE_PARSE
: ifascii
could not be parsed into an IP address.
-
bool
lsdn_ip_eq
(lsdn_ip_t a, lsdn_ip_t b)¶ Compare two lsdn_ip_t for equality.
- Return
true
ifa
andb
are equal,false
otherwise.- Parameters
a
: IP address.b
: IP address.
-
bool
lsdn_ipv_eq
(lsdn_ip_t a, lsdn_ip_t b)¶ Compare two lsdn_ip_t for IP version equality.
- Return
true
if botha
andb
are of the same IP version,false
otherwise.- Parameters
a
: IP address.b
: IP address.
-
void
lsdn_mac_to_string
(const lsdn_mac_t * mac, char * buf)¶ Format lsdn_mac_t as ASCII string.
buf
must be able to hold at least LSDN_MAC_STRING_LEN bytes.- Parameters
mac
: MAC address.buf
: destination buffer for the ASCII string.
-
void
lsdn_ipv4_to_string
(const lsdn_ipv4_t * ipv4, char * buf)¶ Format lsdn_ipv4_t as ASCII string.
buf
must be able to hold at least LSDN_IPv4_STRING_LEN bytes.- Parameters
ipv4
: IPv4 address.buf
: destination buffer for the ASCII string.
-
void
lsdn_ipv6_to_string
(const lsdn_ipv6_t * ipv6, char * buf)¶ Format lsdn_ipv6_t as ASCII string.
buf
must be able to hold at least LSDN_IPv6_STRING_LEN bytes.- Parameters
ipv6
: IPv6 address.buf
: destination buffer for the ASCII string.
-
void
lsdn_ip_to_string
(const lsdn_ip_t * ip, char * buf)¶ Format lsdn_ip_t as ASCII string.
buf
must be able to hold at least LSDN_IP_STRING_LEN bytes.- Parameters
ip
: IP address.buf
: destination buffer for the ASCII string.
-
lsdn_ip_t
lsdn_ip_mask_from_prefix
(enum lsdn_ipv v, int prefix)¶ Return an IPv4/6 address mask for the given network prefix.
Sets
prefix
leading bits to 1 and leaves the rest at 0. For example,lsdn_ipv4_prefix_mask(LSDN_IPV4, 24)
generates address255.255.255.0
.- Return
- IP address mask of the appropriate version.
- Parameters
v
: IP version.prefix
: network prefix number of leading bits to set to 1.
-
bool
lsdn_is_prefix_valid
(enum lsdn_ipv ipv, int prefix)¶ Check if the size of network prefix makes sense for given ip version.
Prefix size must not exceed number of bits of the given address.
- Return
true
ifprefix
makes sense for the IP version,false
otherwise.- Parameters
ipv
: IP version.prefix
: network prefix to check.
-
int
lsdn_ip_prefix_from_mask
(const lsdn_ip_t * mask)¶ Calculate length of prefix from a network mask.
Prefix is a number of leading 1 bits in the mask.
- Return
- number of leading 1 bits.
- Parameters
mask
: network mask to check.
-
bool
lsdn_ip_mask_is_prefix
(const lsdn_ip_t * mask)¶ Check if the given IP address is a valid address mask.
A valid network mask is an IP address which, in bits, is a sequence of 1s followed by a sequence of 0s.
- Return
true
if the IP address is a valid mask,false
otherwise.- Parameters
mask
: address to check.
-
static uint32_t
lsdn_ip4_u32
(const lsdn_ipv4_t * v4)¶ Convert lsdn_ipv4_t to
uint32_t
.- Return
- IP address represented as a single
uint32_t
value. - Parameters
v4
: address to convert.
-
const char *
lsdn_mk_name
(struct lsdn_context *ctx, const char *type)¶ Generate unique name for an object.
The name is based on the context name, type of the object (net, phys, virt, etc.) and a unique object counter on the context. It is in the form
"ctxname-type-12"
.Results are saved in a reused buffer, so every subsequent call overwrites the previous results. Users need to make a copy of the returned string.
- See
- lsdn_mk_net_name, lsdn_mk_phys_name, lsdn_mk_virt_name, lsdn_mk_iface_name, lsdn_mk_settings_name
- Return
- pointer to a buffer with a generated unique name.
- Parameters
ctx
: LSDN contexttype
: object type (arbitrary string, usually “net”, “phys”, “virt”, “iface” or “settings”)
Variables
-
const lsdn_mac_t
lsdn_broadcast_mac
¶ Broadcast MAC address.
Its value is FF:FF:FF:FF:FF:FF.
-
const lsdn_mac_t
lsdn_all_zeroes_mac
¶ All zeroes MAC mask.
Matches every MAC address. Its value, obviously, is all zeroes.
-
const lsdn_mac_t
lsdn_multicast_mac_mask
¶ Multicast MAC address.
Its value is 01:00:00:00:00:00.
-
const lsdn_mac_t
lsdn_single_mac_mask
¶ Single MAC mask.
Network mask that matches a single MAC address. Its value is all ones.
-
union
lsdn_mac
¶ - #include <nettypes.h>
MAC address.
Public Members
-
uint8_t lsdn_mac::bytes[LSDN_MAC_LEN]
address as
uint8_t
.
-
char lsdn_mac::chr[LSDN_MAC_LEN]
address as
char
.
-
-
union
lsdn_ipv4
¶ - #include <nettypes.h>
IPv4 address.
Public Members
-
uint8_t lsdn_ipv4::bytes[LSDN_IPv4_LEN]
address as
uint8_t
.
-
char lsdn_ipv4::chr[LSDN_IPv4_LEN]
address as
char
.
-
-
union
lsdn_ipv6
¶ - #include <nettypes.h>
IPv6 address.
Public Members
-
uint8_t lsdn_ipv6::bytes[LSDN_IPv6_LEN]
address as
uint8_t
.
-
char lsdn_ipv6::chr[LSDN_IPv6_LEN]
address as
char
.
-
-
struct
lsdn_ip
¶ - #include <nettypes.h>
IP address (any version).