X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fdpif-netdev.c;h=60094073e56ca8bf104475aaf2f0c650a94aacdf;hb=d2805da2cb2256e9e2efc5074fbe8df55408213f;hp=4a5b2a7a2dd22b13f34bba701852e1344ac8a608;hpb=2105ccc8503374c12b1d5e4cd6d4b23eb89d4d02;p=openvswitch diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 4a5b2a7a..60094073 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -457,7 +457,7 @@ get_port_by_name(struct dp_netdev *dp, { struct dp_netdev_port *port; - LIST_FOR_EACH (port, struct dp_netdev_port, node, &dp->port_list) { + LIST_FOR_EACH (port, node, &dp->port_list) { if (!strcmp(netdev_get_name(port->netdev), devname)) { *portp = port; return 0; @@ -545,8 +545,7 @@ dp_netdev_flow_flush(struct dp_netdev *dp) { struct dp_netdev_flow *flow, *next; - HMAP_FOR_EACH_SAFE (flow, next, struct dp_netdev_flow, node, - &dp->flow_table) { + HMAP_FOR_EACH_SAFE (flow, next, node, &dp->flow_table) { dp_netdev_free_flow(dp, flow); } } @@ -567,7 +566,7 @@ dpif_netdev_port_list(const struct dpif *dpif, struct odp_port *ports, int n) int i; i = 0; - LIST_FOR_EACH (port, struct dp_netdev_port, node, &dp->port_list) { + LIST_FOR_EACH (port, node, &dp->port_list) { struct odp_port *odp_port = &ports[i]; if (i >= n) { break; @@ -661,8 +660,7 @@ dp_netdev_lookup_flow(const struct dp_netdev *dp, const flow_t *key) struct dp_netdev_flow *flow; assert(!key->reserved[0] && !key->reserved[1] && !key->reserved[2]); - HMAP_FOR_EACH_WITH_HASH (flow, struct dp_netdev_flow, node, - flow_hash(key, 0), &dp->flow_table) { + HMAP_FOR_EACH_WITH_HASH (flow, node, flow_hash(key, 0), &dp->flow_table) { if (flow_equal(&flow->key, key)) { return flow; } @@ -886,7 +884,7 @@ dpif_netdev_flow_list(const struct dpif *dpif, struct odp_flow flows[], int n) int i; i = 0; - HMAP_FOR_EACH (flow, struct dp_netdev_flow, node, &dp->flow_table) { + HMAP_FOR_EACH (flow, node, &dp->flow_table) { if (i >= n) { break; } @@ -1044,10 +1042,10 @@ dp_netdev_run(void) struct dp_netdev *dp; ofpbuf_init(&packet, DP_NETDEV_HEADROOM + max_mtu); - LIST_FOR_EACH (dp, struct dp_netdev, node, &dp_netdev_list) { + LIST_FOR_EACH (dp, node, &dp_netdev_list) { struct dp_netdev_port *port; - LIST_FOR_EACH (port, struct dp_netdev_port, node, &dp->port_list) { + LIST_FOR_EACH (port, node, &dp->port_list) { int error; /* Reset packet contents. */ @@ -1072,9 +1070,9 @@ dp_netdev_wait(void) { struct dp_netdev *dp; - LIST_FOR_EACH (dp, struct dp_netdev, node, &dp_netdev_list) { + LIST_FOR_EACH (dp, node, &dp_netdev_list) { struct dp_netdev_port *port; - LIST_FOR_EACH (port, struct dp_netdev_port, node, &dp->port_list) { + LIST_FOR_EACH (port, node, &dp->port_list) { netdev_recv_wait(port->netdev); } } @@ -1082,7 +1080,7 @@ dp_netdev_wait(void) /* Modify the TCI field of 'packet'. If a VLAN tag is not present, one - * is added with the TCI field set to 'tci'. If a VLAN tag is present, + * is added with the TCI field set to 'tci'. If a VLAN tag is present, * then 'mask' bits are cleared before 'tci' is logically OR'd into the * TCI field. * @@ -1104,7 +1102,6 @@ dp_netdev_modify_vlan_tci(struct ofpbuf *packet, uint16_t tci, uint16_t mask) veh->veth_tci |= htons(tci); } else { /* Insert new 802.1Q header. */ - struct eth_header *eh = packet->l2; struct vlan_eth_header tmp; memcpy(tmp.veth_dst, eh->eth_dst, ETH_ADDR_LEN); memcpy(tmp.veth_src, eh->eth_src, ETH_ADDR_LEN); @@ -1151,19 +1148,25 @@ dp_netdev_set_dl_dst(struct ofpbuf *packet, const uint8_t dl_addr[ETH_ADDR_LEN]) memcpy(eh->eth_dst, dl_addr, sizeof eh->eth_dst); } +static bool +is_ip(const struct ofpbuf *packet, const flow_t *key) +{ + return key->dl_type == htons(ETH_TYPE_IP) && packet->l4; +} + static void dp_netdev_set_nw_addr(struct ofpbuf *packet, const flow_t *key, const struct odp_action_nw_addr *a) { - if (key->dl_type == htons(ETH_TYPE_IP)) { + if (is_ip(packet, key)) { struct ip_header *nh = packet->l3; uint32_t *field; field = a->type == ODPAT_SET_NW_SRC ? &nh->ip_src : &nh->ip_dst; - if (key->nw_proto == IP_TYPE_TCP) { + if (key->nw_proto == IP_TYPE_TCP && packet->l7) { struct tcp_header *th = packet->l4; th->tcp_csum = recalc_csum32(th->tcp_csum, *field, a->nw_addr); - } else if (key->nw_proto == IP_TYPE_UDP) { + } else if (key->nw_proto == IP_TYPE_UDP && packet->l7) { struct udp_header *uh = packet->l4; if (uh->udp_csum) { uh->udp_csum = recalc_csum32(uh->udp_csum, *field, a->nw_addr); @@ -1181,7 +1184,7 @@ static void dp_netdev_set_nw_tos(struct ofpbuf *packet, const flow_t *key, const struct odp_action_nw_tos *a) { - if (key->dl_type == htons(ETH_TYPE_IP)) { + if (is_ip(packet, key)) { struct ip_header *nh = packet->l3; uint8_t *field = &nh->ip_tos; @@ -1198,14 +1201,14 @@ static void dp_netdev_set_tp_port(struct ofpbuf *packet, const flow_t *key, const struct odp_action_tp_port *a) { - if (key->dl_type == htons(ETH_TYPE_IP)) { + if (is_ip(packet, key)) { uint16_t *field; - if (key->nw_proto == IPPROTO_TCP) { + if (key->nw_proto == IPPROTO_TCP && packet->l7) { struct tcp_header *th = packet->l4; field = a->type == ODPAT_SET_TP_SRC ? &th->tcp_src : &th->tcp_dst; th->tcp_csum = recalc_csum16(th->tcp_csum, *field, a->tp_port); *field = a->tp_port; - } else if (key->nw_proto == IPPROTO_UDP) { + } else if (key->nw_proto == IPPROTO_UDP && packet->l7) { struct udp_header *uh = packet->l4; field = a->type == ODPAT_SET_TP_SRC ? &uh->udp_src : &uh->udp_dst; uh->udp_csum = recalc_csum16(uh->udp_csum, *field, a->tp_port); @@ -1256,8 +1259,7 @@ dp_netdev_output_control(struct dp_netdev *dp, const struct ofpbuf *packet, } msg_size = sizeof *header + packet->size; - msg = ofpbuf_new(msg_size + DPIF_RECV_MSG_PADDING); - ofpbuf_reserve(msg, DPIF_RECV_MSG_PADDING); + msg = ofpbuf_new_with_headroom(msg_size, DPIF_RECV_MSG_PADDING); header = ofpbuf_put_uninit(msg, sizeof *header); header->type = queue_no; header->length = msg_size;