- Add support for OpenFlow error message type.
[sliver-openvswitch.git] / include / packets.h
index cf2dc27..ea30a2a 100644 (file)
@@ -34,6 +34,7 @@
 #define PACKETS_H 1
 
 #include <stdint.h>
+#include <string.h>
 #include "util.h"
 
 #define ETH_ADDR_LEN           6
@@ -50,6 +51,15 @@ static inline bool eth_addr_is_local(const uint8_t ea[6])
 {
     return ea[0] & 2;
 }
+static inline bool eth_addr_equals(const uint8_t a[ETH_ADDR_LEN],
+                                   const uint8_t b[ETH_ADDR_LEN]) 
+{
+    return !memcmp(a, b, ETH_ADDR_LEN);
+}
+#define ETH_ADDR_FMT                                                    \
+    "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8
+#define ETH_ADDR_ARGS(ea)                                   \
+    (ea)[0], (ea)[1], (ea)[2], (ea)[3], (ea)[4], (ea)[5]
 
 #define ETH_TYPE_IP            0x0800
 #define ETH_TYPE_ARP           0x0806
@@ -63,7 +73,7 @@ struct eth_header {
     uint8_t eth_dst[ETH_ADDR_LEN];
     uint8_t eth_src[ETH_ADDR_LEN];
     uint16_t eth_type;
-};
+} __attribute__((packed));
 BUILD_ASSERT_DECL(ETH_HEADER_LEN == sizeof(struct eth_header));
 
 #define LLC_DSAP_SNAP 0xaa
@@ -75,7 +85,7 @@ struct llc_header {
     uint8_t llc_dsap;
     uint8_t llc_ssap;
     uint8_t llc_cntl;
-};
+} __attribute__((packed));
 BUILD_ASSERT_DECL(LLC_HEADER_LEN == sizeof(struct llc_header));
 
 #define SNAP_ORG_ETHERNET "\0\0" /* The compiler adds a null byte, so
@@ -91,7 +101,7 @@ BUILD_ASSERT_DECL(SNAP_HEADER_LEN == sizeof(struct snap_header));
 struct llc_snap_header {
     struct llc_header llc;
     struct snap_header snap;
-};
+} __attribute__((packed));
 BUILD_ASSERT_DECL(LLC_SNAP_HEADER_LEN == sizeof(struct llc_snap_header));
 
 #define VLAN_VID 0x0fff
@@ -113,6 +123,13 @@ struct vlan_eth_header {
 };
 BUILD_ASSERT_DECL(VLAN_ETH_HEADER_LEN == sizeof(struct vlan_eth_header));
 
+#define IP_FMT "%"PRIu8".%"PRIu8".%"PRIu8".%"PRIu8
+#define IP_ARGS(ip)                             \
+        ((uint8_t *) ip)[0],                    \
+        ((uint8_t *) ip)[1],                    \
+        ((uint8_t *) ip)[2],                    \
+        ((uint8_t *) ip)[3]
+
 #define IP_VER(ip_ihl_ver) ((ip_ihl_ver) >> 4)
 #define IP_IHL(ip_ihl_ver) ((ip_ihl_ver) & 15)