aboutgitcodebugslistschat
path: root/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'util.h')
-rw-r--r--util.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/util.h b/util.h
index 48f3560..264423b 100644
--- a/util.h
+++ b/util.h
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <stddef.h>
#include <string.h>
#include <signal.h>
@@ -31,6 +32,9 @@
#ifndef ETH_MIN_MTU
#define ETH_MIN_MTU 68
#endif
+#ifndef IP_MAX_MTU
+#define IP_MAX_MTU USHRT_MAX
+#endif
#ifndef MIN
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
@@ -90,6 +94,7 @@
#define PORT_IS_EPHEMERAL(port) ((port) >= PORT_EPHEMERAL_MIN)
#define MAC_ZERO ((uint8_t [ETH_ALEN]){ 0 })
+#define MAC_LAA ((uint8_t [ETH_ALEN]){ BIT(1), 0, 0, 0, 0, 0 })
#define MAC_IS_ZERO(addr) (!memcmp((addr), MAC_ZERO, ETH_ALEN))
#ifndef __bswap_constant_16
@@ -116,7 +121,8 @@ int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int flags,
void *arg);
#define NS_CALL(fn, arg) \
do { \
- char ns_fn_stack[NS_FN_STACK_SIZE]; \
+ char ns_fn_stack[NS_FN_STACK_SIZE] \
+ __attribute__ ((aligned(__alignof__(max_align_t)))); \
\
do_clone((fn), ns_fn_stack, sizeof(ns_fn_stack), \
CLONE_VM | CLONE_VFORK | CLONE_FILES | SIGCHLD,\
@@ -157,6 +163,24 @@ int write_file(const char *path, const char *buf);
int write_remainder(int fd, const struct iovec *iov, int iovcnt, size_t skip);
/**
+ * af_name() - Return name of an address family
+ * @af: Address/protocol family (AF_INET or AF_INET6)
+ *
+ * Returns: Name of the protocol family as a string
+ */
+static inline const char *af_name(sa_family_t af)
+{
+ switch (af) {
+ case AF_INET:
+ return "IPv4";
+ case AF_INET6:
+ return "IPv6";
+ default:
+ return "<unknown address family>";
+ }
+}
+
+/**
* mod_sub() - Modular arithmetic subtraction
* @a: Minued, unsigned value < @m
* @b: Subtrahend, unsigned value < @m