2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 22:35:15 +00:00

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.
This commit is contained in:
Ethan Jackson
2011-03-23 12:59:40 -07:00
parent 15df7ea8d9
commit 40f78b38e7
3 changed files with 26 additions and 16 deletions

View File

@@ -204,24 +204,29 @@ ipv6_is_cidr(const struct in6_addr *netmask)
return true; return true;
} }
/* Populates 'b' with a LACP packet containing 'pdu' with source address /* Populates 'b' with an L2 packet headed with the given 'eth_dst', 'eth_src'
* 'eth_src'. */ * and 'eth_type' paramaters. A payload of 'size' bytes is allocated in 'b'
void * and returned. This payload may be populated with appropriate information by
compose_lacp_packet(struct ofpbuf *b, const uint8_t eth_src[ETH_ADDR_LEN], * the caller. */
const struct lacp_pdu *pdu) 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 eth_header *eth;
struct lacp_pdu *eth_pdu;
ofpbuf_clear(b); ofpbuf_clear(b);
ofpbuf_prealloc_tailroom(b, ETH_HEADER_LEN + LACP_PDU_LEN); ofpbuf_prealloc_tailroom(b, ETH_HEADER_LEN + size);
eth = ofpbuf_put_zeros(b, ETH_HEADER_LEN); eth = ofpbuf_put_uninit(b, ETH_HEADER_LEN);
eth_pdu = ofpbuf_put(b, pdu, LACP_PDU_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); 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'. */ /* Populates 'pdu' with a LACP PDU comprised of 'actor' and 'partner'. */

View File

@@ -412,6 +412,11 @@ struct in6_addr ipv6_create_mask(int mask);
int ipv6_count_cidr_bits(const struct in6_addr *netmask); int ipv6_count_cidr_bits(const struct in6_addr *netmask);
bool ipv6_is_cidr(const struct in6_addr *netmask); bool ipv6_is_cidr(const struct in6_addr *netmask);
void *
compose_packet(struct ofpbuf *, const uint8_t eth_dst[ETH_ADDR_LEN],
const uint8_t eth_src[ETH_ADDR_LEN], uint16_t eth_type,
size_t size);
/* Masks for lacp_info state member. */ /* Masks for lacp_info state member. */
#define LACP_STATE_ACT 0x01 /* Activity. Active or passive? */ #define LACP_STATE_ACT 0x01 /* Activity. Active or passive? */
#define LACP_STATE_TIME 0x02 /* Timeout. Short or long timeout? */ #define LACP_STATE_TIME 0x02 /* Timeout. Short or long timeout? */
@@ -460,9 +465,6 @@ struct lacp_pdu {
} __attribute__((packed)); } __attribute__((packed));
BUILD_ASSERT_DECL(LACP_PDU_LEN == sizeof(struct lacp_pdu)); BUILD_ASSERT_DECL(LACP_PDU_LEN == sizeof(struct lacp_pdu));
void compose_lacp_packet(struct ofpbuf *, const uint8_t eth_src[ETH_ADDR_LEN],
const struct lacp_pdu *);
void compose_lacp_pdu(const struct lacp_info *actor, void compose_lacp_pdu(const struct lacp_info *actor,
const struct lacp_info *partner, struct lacp_pdu *); const struct lacp_info *partner, struct lacp_pdu *);

View File

@@ -3811,9 +3811,12 @@ lacp_send_pdu_cb(void *aux, const struct lacp_pdu *pdu)
error = netdev_get_etheraddr(iface->netdev, ea); error = netdev_get_etheraddr(iface->netdev, ea);
if (!error) { if (!error) {
struct ofpbuf packet; struct ofpbuf packet;
struct lacp_pdu *packet_pdu;
ofpbuf_init(&packet, ETH_HEADER_LEN + LACP_PDU_LEN); ofpbuf_init(&packet, 0);
compose_lacp_packet(&packet, ea, pdu); packet_pdu = compose_packet(&packet, eth_addr_lacp, ea, ETH_TYPE_LACP,
sizeof *packet_pdu);
memcpy(packet_pdu, pdu, sizeof *packet_pdu);
ofproto_send_packet(iface->port->bridge->ofproto, ofproto_send_packet(iface->port->bridge->ofproto,
iface->dp_ifidx, 0, &packet); iface->dp_ifidx, 0, &packet);
ofpbuf_uninit(&packet); ofpbuf_uninit(&packet);