From 62e1ba833c3dcf9e7dc0b179eddc6d5e7e06ab67 Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Thu, 21 May 2009 09:45:47 +0000 Subject: [PATCH] Consolidate and clean up the first section of ip_output.c in light of the last year or two's work on routing: - Combine iproute initialization and flowtable lookup blocks, eliminating unnecessary tests for known-zero'd iproute fields. - Add a comment indicating (a) why the route entry returned by the flowtable is considered stable and (b) that the flowtable lookup must occur after the setup of the mbuf flow ID. - Assert the inpcb lock before any use of inpcb fields. Reviewed by: kmacy --- sys/netinet/ip_output.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 35905e80d42..6e4f8792aad 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -150,20 +150,25 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags, #endif M_ASSERTPKTHDR(m); - if (ro == NULL) { - ro = &iproute; - bzero(ro, sizeof (*ro)); - } - if (inp != NULL) { - M_SETFIB(m, inp->inp_inc.inc_fibnum); INP_LOCK_ASSERT(inp); + M_SETFIB(m, inp->inp_inc.inc_fibnum); if (inp->inp_flags & (INP_HW_FLOWID|INP_SW_FLOWID)) { m->m_pkthdr.flowid = inp->inp_flowid; m->m_flags |= M_FLOWID; } } - if ((ro == &iproute) && (ro->ro_rt == NULL) && (ro->ro_lle == NULL)) { + + if (ro == NULL) { + ro = &iproute; + bzero(ro, sizeof (*ro)); + + /* + * The flow table returns route entries valid for up to 30 + * seconds; we rely on the remainder of ip_output() taking no + * longer than that long for the stability of ro_rt. The + * flow ID assignment must have happened before this point. + */ if (flowtable_lookup(ip_ft, m, ro) == 0) nortfree = 1; }