2201 /** 2202 * netif_receive_skb - process receive buffer from network 2203 * @skb: buffer to process 2204 * 2205 * netif_receive_skb() is the main receive data processing function. 2206 * It always succeeds. The buffer may be dropped during processing 2207 * for congestion control or by the protocol layers. 2208 * 2209 * This function may only be called from softirq context and interrupts 2210 * should be enabled. 2211 * 2212 * Return values (usually ignored): 2213 * NET_RX_SUCCESS: no congestion 2214 * NET_RX_DROP: packet was dropped 2215 */ 2216 int netif_receive_skb(struct sk_buff *skb) 2217 { 2218 struct packet_type *ptype, *pt_prev; 2219 struct net_device *orig_dev; 2220 struct net_device *null_or_orig; 2221 int ret = NET_RX_DROP; 2222 __be16 type; 2223 2224 if (skb->vlan_tci && vlan_hwaccel_do_receive(skb)) 2225 return NET_RX_SUCCESS; 2226 2227 /* if we've gotten here through NAPI, check netpoll */ 2228 if (netpoll_receive_skb(skb)) 2229 return NET_RX_DROP; 2230 2231 if (!skb->tstamp.tv64) 2232 net_timestamp(skb); 2233 2234 if (!skb->iif) 2235 skb->iif = skb->dev->ifindex; 2236 2237 null_or_orig = NULL; 2238 orig_dev = skb->dev; 2239 if (orig_dev->master) { 2240 if (skb_bond_should_drop(skb)) 2241 null_or_orig = orig_dev; /* deliver only exact match */ 2242 else 2243 skb->dev = orig_dev->master; 2244 } 2245 2246 __get_cpu_var(netdev_rx_stat).total++; 2247 2248 skb_reset_network_header(skb); 2249 skb_reset_transport_header(skb); 2250 skb->mac_len = skb->network_header - skb->mac_header; 2251 2252 pt_prev = NULL; 2253 2254 rcu_read_lock(); 2255 2256 #ifdef CONFIG_NET_CLS_ACT 2257 if (skb->tc_verd & TC_NCLS) { 2258 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd); 2259 goto ncls; 2260 } 2261 #endif 2262 2263 list_for_each_entry_rcu(ptype, &ptype_all, list) { 2264 if (ptype->dev == null_or_orig || ptype->dev == skb->dev || 2265 ptype->dev == orig_dev) { 2266 if (pt_prev) 2267 ret = deliver_skb(skb, pt_prev, orig_dev); 2268 pt_prev = ptype; 2269 } 2270 } 2271 2272 #ifdef CONFIG_NET_CLS_ACT 2273 skb = handle_ing(skb, &pt_prev, &ret, orig_dev); 2274 if (!skb) 2275 goto out; 2276 ncls: 2277 #endif 2278 2279 skb = handle_bridge(skb, &pt_prev, &ret, orig_dev); 2280 if (!skb) 2281 goto out; 2282 skb = handle_macvlan(skb, &pt_prev, &ret, orig_dev); 2283 if (!skb) 2284 goto out; 2285 2286 skb_orphan(skb); 2287 2288 type = skb->protocol; 2289 list_for_each_entry_rcu(ptype, 2290 &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) { 2291 if (ptype->type == type && 2292 (ptype->dev == null_or_orig || ptype->dev == skb->dev || 2293 ptype->dev == orig_dev)) { 2294 if (pt_prev) 2295 ret = deliver_skb(skb, pt_prev, orig_dev); 2296 pt_prev = ptype; 2297 } 2298 } 2299 2300 if (pt_prev) { 2301 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev); 2302 } else { 2303 kfree_skb(skb); 2304 /* Jamal, now you will not able to escape explaining 2305 * me how you were going to use this. :-) 2306 */ 2307 ret = NET_RX_DROP; 2308 } 2309 2310 out: 2311 rcu_read_unlock(); 2312 return ret; 2313 } |