Looks Good. Ethan
On Fri, Mar 25, 2011 at 10:35 AM, Ben Pfaff <b...@nicira.com> wrote: > The following commit will introduce the first use of snap_compose(). > --- > lib/packets.c | 52 +++++++++++++++++++++++++++++++++++++++++++++------- > lib/packets.h | 12 +++++++----- > ofproto/ofproto.c | 4 ++-- > vswitchd/bridge.c | 4 ++-- > 4 files changed, 56 insertions(+), 16 deletions(-) > > diff --git a/lib/packets.c b/lib/packets.c > index 6ee7aa8..8cb1b6d 100644 > --- a/lib/packets.c > +++ b/lib/packets.c > @@ -204,14 +204,14 @@ ipv6_is_cidr(const struct in6_addr *netmask) > return true; > } > > -/* 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. */ > +/* Populates 'b' with an Ethernet II packet headed with the given 'eth_dst', > + * 'eth_src' and 'eth_type' parameters. 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) > +eth_compose(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; > @@ -229,6 +229,44 @@ compose_packet(struct ofpbuf *b, const uint8_t > eth_dst[ETH_ADDR_LEN], > return data; > } > > +/* Populates 'b' with an Ethernet LLC+SNAP packet headed with the given > + * 'eth_dst', 'eth_src', 'snap_org', and 'snap_type'. A payload of 'size' > + * bytes is allocated in 'b' and returned. This payload may be populated > with > + * appropriate information by the caller. */ > +void * > +snap_compose(struct ofpbuf *b, const uint8_t eth_dst[ETH_ADDR_LEN], > + const uint8_t eth_src[ETH_ADDR_LEN], > + unsigned int oui, uint16_t snap_type, size_t size) > +{ > + struct eth_header *eth; > + struct llc_snap_header *llc_snap; > + void *payload; > + > + /* Compose basic packet structure. (We need the payload size to stick > into > + * the 802.2 header.) */ > + ofpbuf_clear(b); > + ofpbuf_prealloc_tailroom(b, ETH_HEADER_LEN + LLC_SNAP_HEADER_LEN + size); > + eth = ofpbuf_put_zeros(b, ETH_HEADER_LEN); > + llc_snap = ofpbuf_put_zeros(b, LLC_SNAP_HEADER_LEN); > + payload = ofpbuf_put_uninit(b, size); > + > + /* Compose 802.2 header. */ > + memcpy(eth->eth_dst, eth_dst, ETH_ADDR_LEN); > + memcpy(eth->eth_src, eth_src, ETH_ADDR_LEN); > + eth->eth_type = htons(b->size - ETH_HEADER_LEN); > + > + /* Compose LLC, SNAP headers. */ > + llc_snap->llc.llc_dsap = LLC_DSAP_SNAP; > + llc_snap->llc.llc_ssap = LLC_SSAP_SNAP; > + llc_snap->llc.llc_cntl = LLC_CNTL_SNAP; > + llc_snap->snap.snap_org[0] = oui >> 16; > + llc_snap->snap.snap_org[1] = oui >> 8; > + llc_snap->snap.snap_org[2] = oui; > + llc_snap->snap.snap_type = htons(snap_type); > + > + return payload; > +} > + > /* Populates 'pdu' with a LACP PDU comprised of 'actor' and 'partner'. */ > void > compose_lacp_pdu(const struct lacp_info *actor, > diff --git a/lib/packets.h b/lib/packets.h > index bf071e8..17ef5a6 100644 > --- a/lib/packets.h > +++ b/lib/packets.h > @@ -1,5 +1,5 @@ > /* > - * Copyright (c) 2008, 2009, 2010 Nicira Networks. > + * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks. > * > * Licensed under the Apache License, Version 2.0 (the "License"); > * you may not use this file except in compliance with the License. > @@ -412,10 +412,12 @@ struct in6_addr ipv6_create_mask(int mask); > int ipv6_count_cidr_bits(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); > +void *eth_compose(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); > +void *snap_compose(struct ofpbuf *, const uint8_t eth_dst[ETH_ADDR_LEN], > + const uint8_t eth_src[ETH_ADDR_LEN], > + unsigned int oui, uint16_t snap_type, size_t size); > > /* Masks for lacp_info state member. */ > #define LACP_STATE_ACT 0x01 /* Activity. Active or passive? */ > diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c > index e0715b9..c351425 100644 > --- a/ofproto/ofproto.c > +++ b/ofproto/ofproto.c > @@ -1735,8 +1735,8 @@ ofport_run(struct ofproto *ofproto, struct ofport > *ofport) > struct ccm *ccm; > > ofpbuf_init(&packet, 0); > - ccm = compose_packet(&packet, eth_addr_ccm, ofport->opp.hw_addr, > - ETH_TYPE_CFM, sizeof *ccm); > + ccm = eth_compose(&packet, eth_addr_ccm, ofport->opp.hw_addr, > + ETH_TYPE_CFM, sizeof *ccm); > cfm_compose_ccm(ofport->cfm, ccm); > ofproto_send_packet(ofproto, ofport->odp_port, 0, &packet); > ofpbuf_uninit(&packet); > diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c > index b57860f..c9dc954 100644 > --- a/vswitchd/bridge.c > +++ b/vswitchd/bridge.c > @@ -3814,8 +3814,8 @@ lacp_send_pdu_cb(void *aux, const struct lacp_pdu *pdu) > struct lacp_pdu *packet_pdu; > > ofpbuf_init(&packet, 0); > - packet_pdu = compose_packet(&packet, eth_addr_lacp, ea, > ETH_TYPE_LACP, > - sizeof *packet_pdu); > + packet_pdu = eth_compose(&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, > iface->dp_ifidx, 0, &packet); > -- > 1.7.1 > > _______________________________________________ > dev mailing list > dev@openvswitch.org > http://openvswitch.org/mailman/listinfo/dev > _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev