summaryrefslogtreecommitdiffstats
path: root/vnet/vnet/ip/ip4_packet.h
diff options
context:
space:
mode:
Diffstat (limited to 'vnet/vnet/ip/ip4_packet.h')
-rw-r--r--vnet/vnet/ip/ip4_packet.h119
1 files changed, 88 insertions, 31 deletions
diff --git a/vnet/vnet/ip/ip4_packet.h b/vnet/vnet/ip/ip4_packet.h
index 277b968f9ab..8da788b411f 100644
--- a/vnet/vnet/ip/ip4_packet.h
+++ b/vnet/vnet/ip/ip4_packet.h
@@ -46,7 +46,8 @@
/* IP4 address which can be accessed either as 4 bytes
or as a 32-bit number. */
-typedef union {
+typedef union
+{
u8 data[4];
u32 data_u32;
/* Aliases. */
@@ -54,7 +55,8 @@ typedef union {
u32 as_u32;
} ip4_address_t;
-typedef struct {
+typedef struct
+{
/* IP address must be first for ip_interface_address_get_address() to work */
ip4_address_t ip4_addr;
u32 fib_index;
@@ -69,7 +71,8 @@ ip4_addr_fib_init (ip4_address_fib_t * addr_fib, ip4_address_t * address,
}
/* (src,dst) pair of addresses as found in packet header. */
-typedef struct {
+typedef struct
+{
ip4_address_t src, dst;
} ip4_address_pair_t;
@@ -83,26 +86,46 @@ ip4_address_netmask_length (ip4_address_t * a)
{
switch (a->as_u8[i])
{
- case 0xff: result += 8; break;
- case 0xfe: result += 7; goto done;
- case 0xfc: result += 6; goto done;
- case 0xf8: result += 5; goto done;
- case 0xf0: result += 4; goto done;
- case 0xe0: result += 3; goto done;
- case 0xc0: result += 2; goto done;
- case 0x80: result += 1; goto done;
- case 0x00: result += 0; goto done;
+ case 0xff:
+ result += 8;
+ break;
+ case 0xfe:
+ result += 7;
+ goto done;
+ case 0xfc:
+ result += 6;
+ goto done;
+ case 0xf8:
+ result += 5;
+ goto done;
+ case 0xf0:
+ result += 4;
+ goto done;
+ case 0xe0:
+ result += 3;
+ goto done;
+ case 0xc0:
+ result += 2;
+ goto done;
+ case 0x80:
+ result += 1;
+ goto done;
+ case 0x00:
+ result += 0;
+ goto done;
default:
/* Not a valid netmask mask. */
return ~0;
}
}
- done:
+done:
return result;
}
-typedef union {
- struct {
+typedef union
+{
+ struct
+ {
/* 4 bit packet length (in 32bit units) and version VVVVLLLL.
e.g. for packets w/ no options ip_version_and_header_length == 0x45. */
u8 ip_version_and_header_length;
@@ -133,25 +156,31 @@ typedef union {
u16 checksum;
/* Source and destination address. */
- union {
- struct {
+ union
+ {
+ struct
+ {
ip4_address_t src_address, dst_address;
};
ip4_address_pair_t address_pair;
- };
+ };
};
/* For checksumming we'll want to access IP header in word sized chunks. */
/* For 64 bit machines. */
+ /* *INDENT-OFF* */
CLIB_PACKED (struct {
u64 checksum_data_64[2];
u32 checksum_data_64_32[1];
});
+ /* *INDENT-ON* */
/* For 32 bit machines. */
+ /* *INDENT-OFF* */
CLIB_PACKED (struct {
u32 checksum_data_32[5];
});
+ /* *INDENT-ON* */
} ip4_header_t;
/* Value of ip_version_and_header_length for packets w/o options. */
@@ -160,35 +189,50 @@ typedef union {
always_inline int
ip4_get_fragment_offset (ip4_header_t * i)
-{ return clib_net_to_host_u16 (i->flags_and_fragment_offset) & 0x1fff; }
+{
+ return clib_net_to_host_u16 (i->flags_and_fragment_offset) & 0x1fff;
+}
always_inline int
ip4_get_fragment_more (ip4_header_t * i)
-{ return clib_net_to_host_u16 (i->flags_and_fragment_offset) & IP4_HEADER_FLAG_MORE_FRAGMENTS; }
+{
+ return clib_net_to_host_u16 (i->flags_and_fragment_offset) &
+ IP4_HEADER_FLAG_MORE_FRAGMENTS;
+}
always_inline int
ip4_is_fragment (ip4_header_t * i)
-{ return (i->flags_and_fragment_offset &
- clib_net_to_host_u16 (0x1fff | IP4_HEADER_FLAG_MORE_FRAGMENTS)); }
+{
+ return (i->flags_and_fragment_offset &
+ clib_net_to_host_u16 (0x1fff | IP4_HEADER_FLAG_MORE_FRAGMENTS));
+}
always_inline int
ip4_is_first_fragment (ip4_header_t * i)
-{ return (i->flags_and_fragment_offset &
- clib_net_to_host_u16 (0x1fff | IP4_HEADER_FLAG_MORE_FRAGMENTS)) ==
- clib_net_to_host_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS); }
+{
+ return (i->flags_and_fragment_offset &
+ clib_net_to_host_u16 (0x1fff | IP4_HEADER_FLAG_MORE_FRAGMENTS)) ==
+ clib_net_to_host_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS);
+}
/* Fragment offset in bytes. */
always_inline int
ip4_get_fragment_offset_bytes (ip4_header_t * i)
-{ return 8 * ip4_get_fragment_offset (i); }
+{
+ return 8 * ip4_get_fragment_offset (i);
+}
always_inline int
ip4_header_bytes (ip4_header_t * i)
-{ return sizeof (u32) * (i->ip_version_and_header_length & 0xf); }
+{
+ return sizeof (u32) * (i->ip_version_and_header_length & 0xf);
+}
always_inline void *
ip4_next_header (ip4_header_t * i)
-{ return (void *) i + ip4_header_bytes (i); }
+{
+ return (void *) i + ip4_header_bytes (i);
+}
always_inline u16
ip4_header_checksum (ip4_header_t * i)
@@ -213,7 +257,9 @@ ip4_header_checksum (ip4_header_t * i)
static inline uword
ip4_header_checksum_is_valid (ip4_header_t * i)
-{ return i->checksum == ip4_header_checksum (i); }
+{
+ return i->checksum == ip4_header_checksum (i);
+}
#define ip4_partial_header_checksum_x1(ip0,sum0) \
do { \
@@ -261,10 +307,13 @@ do { \
always_inline uword
ip4_address_is_multicast (ip4_address_t * a)
-{ return (a->data[0] & 0xf0) == 0xe0; }
+{
+ return (a->data[0] & 0xf0) == 0xe0;
+}
always_inline void
-ip4_multicast_address_set_for_group (ip4_address_t * a, ip_multicast_group_t g)
+ip4_multicast_address_set_for_group (ip4_address_t * a,
+ ip_multicast_group_t g)
{
ASSERT ((u32) g < (1 << 28));
a->as_u32 = clib_host_to_net_u32 ((0xe << 28) + g);
@@ -325,3 +374,11 @@ ip4_tcp_reply_x2 (ip4_header_t * ip0, ip4_header_t * ip1,
}
#endif /* included_ip4_packet_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */