aboutsummaryrefslogtreecommitdiff
path: root/lib/packets.c
diff options
context:
space:
mode:
authorEthan Jackson <ethan@nicira.com>2011-03-23 12:59:40 -0700
committerEthan Jackson <ethan@nicira.com>2011-03-23 13:16:38 -0700
commit40f78b38e745019e08b3cfe06ddf205f0cc4b970 (patch)
tree896946ba72966d9eaed199718a841c3ead8f5640 /lib/packets.c
parent15df7ea8d9a338113fc0bd8d2a0a841ec7ce4b6c (diff)
packets: Create new compose_packet() function.
This commit generalizes compose_lacp_packet() into new compose_packet() function. This new function will be used to send CCM messages in future patches.
Diffstat (limited to 'lib/packets.c')
-rw-r--r--lib/packets.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/packets.c b/lib/packets.c
index 60ee3903..6ee7aa83 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -204,24 +204,29 @@ ipv6_is_cidr(const struct in6_addr *netmask)
return true;
}
-/* Populates 'b' with a LACP packet containing 'pdu' with source address
- * 'eth_src'. */
-void
-compose_lacp_packet(struct ofpbuf *b, const uint8_t eth_src[ETH_ADDR_LEN],
- const struct lacp_pdu *pdu)
+/* Populates 'b' with an L2 packet headed with the given 'eth_dst', 'eth_src'
+ * and 'eth_type' paramaters. A payload of 'size' bytes is allocated in 'b'
+ * and returned. This payload may be populated with appropriate information by
+ * the caller. */
+void *
+compose_packet(struct ofpbuf *b, const uint8_t eth_dst[ETH_ADDR_LEN],
+ const uint8_t eth_src[ETH_ADDR_LEN], uint16_t eth_type,
+ size_t size)
{
+ void *data;
struct eth_header *eth;
- struct lacp_pdu *eth_pdu;
ofpbuf_clear(b);
- ofpbuf_prealloc_tailroom(b, ETH_HEADER_LEN + LACP_PDU_LEN);
- eth = ofpbuf_put_zeros(b, ETH_HEADER_LEN);
- eth_pdu = ofpbuf_put(b, pdu, LACP_PDU_LEN);
+ ofpbuf_prealloc_tailroom(b, ETH_HEADER_LEN + size);
+ eth = ofpbuf_put_uninit(b, ETH_HEADER_LEN);
+ data = ofpbuf_put_uninit(b, size);
- memcpy(eth->eth_dst, eth_addr_lacp, ETH_ADDR_LEN);
+ memcpy(eth->eth_dst, eth_dst, ETH_ADDR_LEN);
memcpy(eth->eth_src, eth_src, ETH_ADDR_LEN);
- eth->eth_type = htons(ETH_TYPE_LACP);
+ eth->eth_type = htons(eth_type);
+
+ return data;
}
/* Populates 'pdu' with a LACP PDU comprised of 'actor' and 'partner'. */