X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fpackets.c;h=6ee7aa83ecbbefdff365e31b4681ccbb770f7eaa;hb=b0421aa20c401c8503946a102428d0a4adb976f9;hp=8791a3ce09a244b20719a484a23d30eeaa191d21;hpb=8834f25e9983910258cd0cd1e400a14d9a664479;p=openvswitch diff --git a/lib/packets.c b/lib/packets.c index 8791a3ce..6ee7aa83 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -204,25 +204,37 @@ ipv6_is_cidr(const struct in6_addr *netmask) return true; } -/* Fills 'b' with a LACP packet whose source address is 'eth_src', LACP actor - * information is 'actor', and LACP partner information is 'partner'. */ -void -compose_lacp_packet(struct ofpbuf *b, struct lacp_info *actor, - struct lacp_info *partner, - const uint8_t eth_src[ETH_ADDR_LEN]) +/* 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 *pdu; ofpbuf_clear(b); - ofpbuf_prealloc_tailroom(b, ETH_HEADER_LEN + LACP_PDU_LEN); - eth = ofpbuf_put_zeros(b, ETH_HEADER_LEN); - pdu = ofpbuf_put_zeros(b, 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'. */ +void +compose_lacp_pdu(const struct lacp_info *actor, + const struct lacp_info *partner, struct lacp_pdu *pdu) +{ + memset(pdu, 0, sizeof *pdu); pdu->subtype = 1; pdu->version = 1;