From 1dfdb9b3177474aacd8b81aadf8cc6df5493d851 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Thu, 31 Oct 2013 16:23:13 -0700 Subject: [PATCH] ofproto: Retrieve ipfix, sflow and netflow in xlate_receive(). This seems cleaner than having separate accessors for them. Signed-off-by: Ethan Jackson Acked-by: Ben Pfaff --- ofproto/ofproto-dpif-upcall.c | 11 +++---- ofproto/ofproto-dpif-xlate.c | 60 +++++++++++------------------------ ofproto/ofproto-dpif-xlate.h | 9 ++---- ofproto/ofproto-dpif.c | 4 +-- 4 files changed, 28 insertions(+), 56 deletions(-) diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index 3f9ad58bc..0e25dee36 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -634,7 +634,7 @@ handle_upcalls(struct udpif *udpif, struct list *upcalls) error = xlate_receive(udpif->backer, packet, dupcall->key, dupcall->key_len, &flow, &miss->key_fitness, - &ofproto, &odp_in_port); + &ofproto, &ipfix, &sflow, NULL, &odp_in_port); if (error) { if (error == ENODEV) { struct drop_key *drop_key; @@ -701,7 +701,6 @@ handle_upcalls(struct udpif *udpif, struct list *upcalls) switch (type) { case SFLOW_UPCALL: - sflow = xlate_get_sflow(ofproto); if (sflow) { union user_action_cookie cookie; @@ -710,18 +709,14 @@ handle_upcalls(struct udpif *udpif, struct list *upcalls) sizeof cookie.sflow); dpif_sflow_received(sflow, dupcall->packet, &flow, odp_in_port, &cookie); - dpif_sflow_unref(sflow); } break; case IPFIX_UPCALL: - ipfix = xlate_get_ipfix(ofproto); if (ipfix) { dpif_ipfix_bridge_sample(ipfix, dupcall->packet, &flow); - dpif_ipfix_unref(ipfix); } break; case FLOW_SAMPLE_UPCALL: - ipfix = xlate_get_ipfix(ofproto); if (ipfix) { union user_action_cookie cookie; @@ -736,7 +731,6 @@ handle_upcalls(struct udpif *udpif, struct list *upcalls) cookie.flow_sample.probability, cookie.flow_sample.obs_domain_id, cookie.flow_sample.obs_point_id); - dpif_ipfix_unref(ipfix); } break; case BAD_UPCALL: @@ -745,6 +739,9 @@ handle_upcalls(struct udpif *udpif, struct list *upcalls) NOT_REACHED(); } + dpif_ipfix_unref(ipfix); + dpif_sflow_unref(sflow); + list_remove(&upcall->list_node); upcall_destroy(upcall); } diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index ac273e944..cea46583e 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -514,8 +514,10 @@ xlate_ofport_remove(struct ofport_dpif *ofport) * respectively), populates 'flow' with the result of odp_flow_key_to_flow(). * Optionally, if nonnull, populates 'fitnessp' with the fitness of 'flow' as * returned by odp_flow_key_to_flow(). Also, optionally populates 'ofproto' - * with the ofproto_dpif, and 'odp_in_port' with the datapath in_port, that - * 'packet' ingressed. + * with the ofproto_dpif, 'odp_in_port' with the datapath in_port, that + * 'packet' ingressed, and 'ipfix', 'sflow', and 'netflow' with the appropriate + * handles for those protocols if they're enabled. Caller is responsible for + * unrefing them. * * If 'ofproto' is nonnull, requires 'flow''s in_port to exist. Otherwise sets * 'flow''s in_port to OFPP_NONE. @@ -537,7 +539,9 @@ int xlate_receive(const struct dpif_backer *backer, struct ofpbuf *packet, const struct nlattr *key, size_t key_len, struct flow *flow, enum odp_key_fitness *fitnessp, - struct ofproto_dpif **ofproto, odp_port_t *odp_in_port) + struct ofproto_dpif **ofproto, struct dpif_ipfix **ipfix, + struct dpif_sflow **sflow, struct netflow **netflow, + odp_port_t *odp_in_port) { enum odp_key_fitness fitness; const struct xport *xport; @@ -591,6 +595,18 @@ xlate_receive(const struct dpif_backer *backer, struct ofpbuf *packet, *ofproto = xport->xbridge->ofproto; } + if (ipfix) { + *ipfix = dpif_ipfix_ref(xport->xbridge->ipfix); + } + + if (sflow) { + *sflow = dpif_sflow_ref(xport->xbridge->sflow); + } + + if (netflow) { + *netflow = netflow_ref(xport->xbridge->netflow); + } + exit: if (fitnessp) { *fitnessp = fitness; @@ -2910,44 +2926,6 @@ xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src) ofpbuf_put(&dst->odp_actions, src->odp_actions.data, src->odp_actions.size); } - -/* Returns a reference to the sflow handled associated with ofproto, or NULL if - * there is none. The caller is responsible for decrementing the results ref - * count with dpif_sflow_unref(). */ -struct dpif_sflow * -xlate_get_sflow(const struct ofproto_dpif *ofproto) -{ - struct dpif_sflow *sflow = NULL; - struct xbridge *xbridge; - - ovs_rwlock_rdlock(&xlate_rwlock); - xbridge = xbridge_lookup(ofproto); - if (xbridge) { - sflow = dpif_sflow_ref(xbridge->sflow); - } - ovs_rwlock_unlock(&xlate_rwlock); - - return sflow; -} - -/* Returns a reference to the ipfix handled associated with ofproto, or NULL if - * there is none. The caller is responsible for decrementing the results ref - * count with dpif_ipfix_unref(). */ -struct dpif_ipfix * -xlate_get_ipfix(const struct ofproto_dpif *ofproto) -{ - struct dpif_ipfix *ipfix = NULL; - struct xbridge *xbridge; - - ovs_rwlock_rdlock(&xlate_rwlock); - xbridge = xbridge_lookup(ofproto); - if (xbridge) { - ipfix = dpif_ipfix_ref(xbridge->ipfix); - } - ovs_rwlock_unlock(&xlate_rwlock); - - return ipfix; -} static struct skb_priority_to_dscp * get_skb_priority(const struct xport *xport, uint32_t skb_priority) diff --git a/ofproto/ofproto-dpif-xlate.h b/ofproto/ofproto-dpif-xlate.h index 11a180ae0..27bfa74a5 100644 --- a/ofproto/ofproto-dpif-xlate.h +++ b/ofproto/ofproto-dpif-xlate.h @@ -147,7 +147,9 @@ void xlate_ofport_remove(struct ofport_dpif *) OVS_REQ_WRLOCK(xlate_rwlock); int xlate_receive(const struct dpif_backer *, struct ofpbuf *packet, const struct nlattr *key, size_t key_len, struct flow *, enum odp_key_fitness *, - struct ofproto_dpif **, odp_port_t *odp_in_port) + struct ofproto_dpif **, struct dpif_ipfix **, + struct dpif_sflow **, struct netflow **, + odp_port_t *odp_in_port) OVS_EXCLUDED(xlate_rwlock); void xlate_actions(struct xlate_in *, struct xlate_out *) @@ -159,11 +161,6 @@ void xlate_out_uninit(struct xlate_out *); void xlate_actions_for_side_effects(struct xlate_in *); void xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src); -struct dpif_sflow *xlate_get_sflow(const struct ofproto_dpif *) - OVS_EXCLUDED(xlate_rwlock); -struct dpif_ipfix *xlate_get_ipfix(const struct ofproto_dpif *) - OVS_EXCLUDED(xlate_rwlock); - int xlate_send_packet(const struct ofport_dpif *, struct ofpbuf *); #endif /* ofproto-dpif-xlate.h */ diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 9168da1df..ee08fb560 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -4201,7 +4201,7 @@ facet_revalidate(struct facet *facet) error = xlate_receive(ofproto->backer, NULL, subfacet->key, subfacet->key_len, &recv_flow, NULL, - &recv_ofproto, NULL); + &recv_ofproto, NULL, NULL, NULL, NULL); if (error || recv_ofproto != ofproto || facet != facet_find(ofproto, &recv_flow)) { @@ -5358,7 +5358,7 @@ parse_flow_and_packet(int argc, const char *argv[], } if (xlate_receive(backer, NULL, odp_key.data, odp_key.size, flow, - NULL, ofprotop, NULL)) { + NULL, ofprotop, NULL, NULL, NULL, NULL)) { error = "Invalid datapath flow"; goto exit; } -- 2.43.0