X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fdpif-netdev.c;h=3c22e6dc1b72dc1af770a5b007ce523c78ae9d50;hb=abfec865566e6cce961cc8660de1ddfdc85dae5f;hp=1cab12ba163e78cc998782be0f1c126b864c51b6;hpb=834377ea559d665520910968358c522f30d3eb93;p=openvswitch diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 1cab12ba..3c22e6dc 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -22,8 +22,9 @@ #include #include #include -#include #include +#include +#include #include #include #include @@ -44,9 +45,9 @@ #include "queue.h" #include "timeval.h" #include "util.h" - #include "vlog.h" -#define THIS_MODULE VLM_dpif_netdev + +VLOG_DEFINE_THIS_MODULE(dpif_netdev) /* Configuration parameters. */ enum { N_QUEUES = 2 }; /* Number of queues for dpif_recv(). */ @@ -98,10 +99,9 @@ struct dp_netdev_flow { flow_t key; /* Statistics. */ - struct timeval used; /* Last used time, in milliseconds. */ + struct timespec used; /* Last used time. */ long long int packet_count; /* Number of packets matched. */ long long int byte_count; /* Number of bytes matched. */ - uint8_t ip_tos; /* IP TOS value. */ uint16_t tcp_ctl; /* Bitwise-OR of seen tcp_ctl values. */ /* Actions. */ @@ -137,7 +137,7 @@ static int do_del_port(struct dp_netdev *, uint16_t port_no); static int dp_netdev_output_control(struct dp_netdev *, const struct ofpbuf *, int queue_no, int port_no, uint32_t arg); static int dp_netdev_execute_actions(struct dp_netdev *, - struct ofpbuf *, flow_t *, + struct ofpbuf *, const flow_t *, const union odp_action *, int n); static struct dpif_netdev * @@ -374,11 +374,8 @@ do_add_port(struct dp_netdev *dp, const char *devname, uint16_t flags, memset(&netdev_options, 0, sizeof netdev_options); netdev_options.name = devname; netdev_options.ethertype = NETDEV_ETH_TYPE_ANY; - netdev_options.may_create = true; if (internal) { netdev_options.type = "tap"; - } else { - netdev_options.may_open = true; } error = netdev_open(&netdev_options, &netdev); @@ -682,9 +679,9 @@ answer_flow_query(struct dp_netdev_flow *flow, uint32_t query_flags, odp_flow->stats.n_packets = flow->packet_count; odp_flow->stats.n_bytes = flow->byte_count; odp_flow->stats.used_sec = flow->used.tv_sec; - odp_flow->stats.used_nsec = flow->used.tv_usec * 1000; + odp_flow->stats.used_nsec = flow->used.tv_nsec; odp_flow->stats.tcp_flags = TCP_FLAGS(flow->tcp_ctl); - odp_flow->stats.ip_tos = flow->ip_tos; + odp_flow->stats.reserved = 0; odp_flow->stats.error = 0; if (odp_flow->n_actions > 0) { unsigned int n = MIN(odp_flow->n_actions, flow->n_actions); @@ -720,58 +717,64 @@ static int dpif_netdev_validate_actions(const union odp_action *actions, int n_actions, bool *mutates) { - unsigned int i; + unsigned int i; *mutates = false; - for (i = 0; i < n_actions; i++) { - const union odp_action *a = &actions[i]; - switch (a->type) { - case ODPAT_OUTPUT: - if (a->output.port >= MAX_PORTS) { - return EINVAL; + for (i = 0; i < n_actions; i++) { + const union odp_action *a = &actions[i]; + switch (a->type) { + case ODPAT_OUTPUT: + if (a->output.port >= MAX_PORTS) { + return EINVAL; } - break; + break; - case ODPAT_OUTPUT_GROUP: + case ODPAT_OUTPUT_GROUP: *mutates = true; - if (a->output_group.group >= N_GROUPS) { - return EINVAL; + if (a->output_group.group >= N_GROUPS) { + return EINVAL; } - break; + break; case ODPAT_CONTROLLER: break; - case ODPAT_SET_VLAN_VID: + case ODPAT_SET_VLAN_VID: *mutates = true; - if (a->vlan_vid.vlan_vid & htons(~VLAN_VID_MASK)) { - return EINVAL; + if (a->vlan_vid.vlan_vid & htons(~VLAN_VID_MASK)) { + return EINVAL; } - break; + break; - case ODPAT_SET_VLAN_PCP: + case ODPAT_SET_VLAN_PCP: *mutates = true; - if (a->vlan_pcp.vlan_pcp & ~VLAN_PCP_MASK) { - return EINVAL; + if (a->vlan_pcp.vlan_pcp & ~(VLAN_PCP_MASK >> VLAN_PCP_SHIFT)) { + return EINVAL; } - break; + break; + + case ODPAT_SET_NW_TOS: + *mutates = true; + if (a->nw_tos.nw_tos & IP_ECN_MASK) { + return EINVAL; + } + break; case ODPAT_STRIP_VLAN: case ODPAT_SET_DL_SRC: case ODPAT_SET_DL_DST: case ODPAT_SET_NW_SRC: case ODPAT_SET_NW_DST: - case ODPAT_SET_NW_TOS: case ODPAT_SET_TP_SRC: case ODPAT_SET_TP_DST: *mutates = true; break; - default: + default: return EOPNOTSUPP; - } - } - return 0; + } + } + return 0; } static int @@ -822,10 +825,9 @@ static void clear_stats(struct dp_netdev_flow *flow) { flow->used.tv_sec = 0; - flow->used.tv_usec = 0; + flow->used.tv_nsec = 0; flow->packet_count = 0; flow->byte_count = 0; - flow->ip_tos = 0; flow->tcp_ctl = 0; } @@ -926,7 +928,7 @@ dpif_netdev_execute(struct dpif *dpif, uint16_t in_port, * if we don't. */ copy = *packet; } - flow_extract(©, in_port, &flow); + flow_extract(©, 0, in_port, &flow); error = dp_netdev_execute_actions(dp, ©, &flow, actions, n_actions); if (mutates) { ofpbuf_uninit(©); @@ -999,17 +1001,12 @@ static void dp_netdev_flow_used(struct dp_netdev_flow *flow, const flow_t *key, const struct ofpbuf *packet) { - time_timeval(&flow->used); + time_timespec(&flow->used); flow->packet_count++; flow->byte_count += packet->size; - if (key->dl_type == htons(ETH_TYPE_IP)) { - struct ip_header *nh = packet->l3; - flow->ip_tos = nh->ip_tos; - - if (key->nw_proto == IPPROTO_TCP) { - struct tcp_header *th = packet->l4; - flow->tcp_ctl |= th->tcp_ctl; - } + if (key->dl_type == htons(ETH_TYPE_IP) && key->nw_proto == IPPROTO_TCP) { + struct tcp_header *th = packet->l4; + flow->tcp_ctl |= th->tcp_ctl; } } @@ -1020,7 +1017,7 @@ dp_netdev_port_input(struct dp_netdev *dp, struct dp_netdev_port *port, struct dp_netdev_flow *flow; flow_t key; - if (flow_extract(packet, port->port_no, &key) && dp->drop_frags) { + if (flow_extract(packet, 0, port->port_no, &key) && dp->drop_frags) { dp->n_frags++; return; } @@ -1080,14 +1077,23 @@ 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, + * then 'mask' bits are cleared before 'tci' is logically OR'd into the + * TCI field. + * + * Note that the function does not ensure that 'tci' does not affect + * bits outside of 'mask'. + */ static void -dp_netdev_modify_vlan_tci(struct ofpbuf *packet, flow_t *key, +dp_netdev_modify_vlan_tci(struct ofpbuf *packet, const flow_t *key, uint16_t tci, uint16_t mask) { struct vlan_eth_header *veh; if (key->dl_vlan != htons(ODP_VLAN_NONE)) { - /* Modify 'mask' bits, but maintain other TCI bits. */ + /* Clear 'mask' bits, but maintain other TCI bits. */ veh = packet->l2; veh->veth_tci &= ~htons(mask); veh->veth_tci |= htons(tci); @@ -1105,12 +1111,10 @@ dp_netdev_modify_vlan_tci(struct ofpbuf *packet, flow_t *key, memcpy(veh, &tmp, sizeof tmp); packet->l2 = (char*)packet->l2 - VLAN_HEADER_LEN; } - - key->dl_vlan = veh->veth_tci & htons(VLAN_VID_MASK); } static void -dp_netdev_strip_vlan(struct ofpbuf *packet, flow_t *key) +dp_netdev_strip_vlan(struct ofpbuf *packet) { struct vlan_eth_header *veh = packet->l2; if (veh->veth_type == htons(ETH_TYPE_VLAN)) { @@ -1124,29 +1128,25 @@ dp_netdev_strip_vlan(struct ofpbuf *packet, flow_t *key) packet->data = (char*)packet->data + VLAN_HEADER_LEN; packet->l2 = (char*)packet->l2 + VLAN_HEADER_LEN; memcpy(packet->data, &tmp, sizeof tmp); - - key->dl_vlan = htons(ODP_VLAN_NONE); } } static void -dp_netdev_set_dl_src(struct ofpbuf *packet, - const uint8_t dl_addr[ETH_ADDR_LEN]) +dp_netdev_set_dl_src(struct ofpbuf *packet, const uint8_t dl_addr[ETH_ADDR_LEN]) { struct eth_header *eh = packet->l2; memcpy(eh->eth_src, dl_addr, sizeof eh->eth_src); } static void -dp_netdev_set_dl_dst(struct ofpbuf *packet, - const uint8_t dl_addr[ETH_ADDR_LEN]) +dp_netdev_set_dl_dst(struct ofpbuf *packet, const uint8_t dl_addr[ETH_ADDR_LEN]) { struct eth_header *eh = packet->l2; memcpy(eh->eth_dst, dl_addr, sizeof eh->eth_dst); } static void -dp_netdev_set_nw_addr(struct ofpbuf *packet, flow_t *key, +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)) { @@ -1172,15 +1172,15 @@ dp_netdev_set_nw_addr(struct ofpbuf *packet, flow_t *key, } static void -dp_netdev_set_nw_tos(struct ofpbuf *packet, flow_t *key, +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)) { struct ip_header *nh = packet->l3; uint8_t *field = &nh->ip_tos; - /* We only set the lower 6 bits. */ - uint8_t new = (a->nw_tos & 0x3f) | (nh->ip_tos & 0xc0); + /* Set the DSCP bits and preserve the ECN bits. */ + uint8_t new = a->nw_tos | (nh->ip_tos & IP_ECN_MASK); nh->ip_csum = recalc_csum16(nh->ip_csum, htons((uint16_t)*field), htons((uint16_t)a->nw_tos)); @@ -1189,7 +1189,7 @@ dp_netdev_set_nw_tos(struct ofpbuf *packet, flow_t *key, } static void -dp_netdev_set_tp_port(struct ofpbuf *packet, flow_t *key, +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)) { @@ -1204,6 +1204,8 @@ dp_netdev_set_tp_port(struct ofpbuf *packet, flow_t *key, 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); *field = a->tp_port; + } else { + return; } } } @@ -1248,7 +1250,8 @@ dp_netdev_output_control(struct dp_netdev *dp, const struct ofpbuf *packet, } msg_size = sizeof *header + packet->size; - msg = ofpbuf_new(msg_size); + msg = ofpbuf_new(msg_size + DPIF_RECV_MSG_PADDING); + ofpbuf_reserve(msg, DPIF_RECV_MSG_PADDING); header = ofpbuf_put_uninit(msg, sizeof *header); header->type = queue_no; header->length = msg_size; @@ -1262,7 +1265,7 @@ dp_netdev_output_control(struct dp_netdev *dp, const struct ofpbuf *packet, static int dp_netdev_execute_actions(struct dp_netdev *dp, - struct ofpbuf *packet, flow_t *key, + struct ofpbuf *packet, const flow_t *key, const union odp_action *actions, int n_actions) { int i; @@ -1290,12 +1293,13 @@ dp_netdev_execute_actions(struct dp_netdev *dp, break; case ODPAT_SET_VLAN_PCP: - dp_netdev_modify_vlan_tci(packet, key, a->vlan_pcp.vlan_pcp << 13, - VLAN_PCP_MASK); + dp_netdev_modify_vlan_tci( + packet, key, a->vlan_pcp.vlan_pcp << VLAN_PCP_SHIFT, + VLAN_PCP_MASK); break; case ODPAT_STRIP_VLAN: - dp_netdev_strip_vlan(packet, key); + dp_netdev_strip_vlan(packet); break; case ODPAT_SET_DL_SRC: @@ -1355,6 +1359,7 @@ const struct dpif_class dpif_netdev_class = { dpif_netdev_recv_set_mask, NULL, /* get_sflow_probability */ NULL, /* set_sflow_probability */ + NULL, /* queue_to_priority */ dpif_netdev_recv, dpif_netdev_recv_wait, };