diff options
author | Joe Stringer <joe@wand.net.nz> | 2012-05-29 11:07:16 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2012-05-29 11:08:11 -0700 |
commit | 3b4d8ad3070ad30da9cf52d4f2abf792bc07f20d (patch) | |
tree | 49a45874265e40b61c446f097eb8889db75a718e /lib/packets.c | |
parent | 518852130bdf45522f76afe7d500a3c0e02d46e3 (diff) |
packets: Adds ethernet-matching helper functions
With OpenFlow 1.1 requiring arbitrary ethernet match support, it simplifies
other code if we have some extra helper functions. This patch adds
eth_mask_is_exact(mask), eth_addr_bitand(src, mask, dst),
eth_addr_equal_except(a, b, mask) and eth_format_masked(eth, mask, output).
Signed-off-by: Joe Stringer <joe@wand.net.nz>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/packets.c')
-rw-r--r-- | lib/packets.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/packets.c b/lib/packets.c index 84ca590b..b3851280 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -148,6 +148,28 @@ eth_from_hex(const char *hex, struct ofpbuf **packetp) return NULL; } +void +eth_format_masked(const uint8_t eth[ETH_ADDR_LEN], + const uint8_t mask[ETH_ADDR_LEN], struct ds *s) +{ + ds_put_format(s, ETH_ADDR_FMT, ETH_ADDR_ARGS(eth)); + if (mask) { + ds_put_format(s, "/"ETH_ADDR_FMT, ETH_ADDR_ARGS(mask)); + } +} + +void +eth_addr_bitand(const uint8_t src[ETH_ADDR_LEN], + const uint8_t mask[ETH_ADDR_LEN], + uint8_t dst[ETH_ADDR_LEN]) +{ + int i; + + for (i = 0; i < ETH_ADDR_LEN; i++) { + dst[i] = src[i] & mask[i]; + } +} + /* Given the IP netmask 'netmask', returns the number of bits of the IP address * that it specifies, that is, the number of 1-bits in 'netmask'. 'netmask' * must be a CIDR netmask (see ip_is_cidr()). */ |