diff options
Diffstat (limited to 'net/core/dev.c')
-rw-r--r-- | net/core/dev.c | 93 |
1 files changed, 88 insertions, 5 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index 09c66a449da6..382df6c09eec 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -132,6 +132,9 @@ | |||
132 | /* Instead of increasing this, you should create a hash table. */ | 132 | /* Instead of increasing this, you should create a hash table. */ |
133 | #define MAX_GRO_SKBS 8 | 133 | #define MAX_GRO_SKBS 8 |
134 | 134 | ||
135 | /* This should be increased if a protocol with a bigger head is added. */ | ||
136 | #define GRO_MAX_HEAD (MAX_HEADER + 128) | ||
137 | |||
135 | /* | 138 | /* |
136 | * The list of packet types we will receive (as opposed to discard) | 139 | * The list of packet types we will receive (as opposed to discard) |
137 | * and the routines to invoke. | 140 | * and the routines to invoke. |
@@ -2345,7 +2348,7 @@ static int napi_gro_complete(struct sk_buff *skb) | |||
2345 | struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK]; | 2348 | struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK]; |
2346 | int err = -ENOENT; | 2349 | int err = -ENOENT; |
2347 | 2350 | ||
2348 | if (!skb_shinfo(skb)->frag_list) | 2351 | if (NAPI_GRO_CB(skb)->count == 1) |
2349 | goto out; | 2352 | goto out; |
2350 | 2353 | ||
2351 | rcu_read_lock(); | 2354 | rcu_read_lock(); |
@@ -2365,6 +2368,7 @@ static int napi_gro_complete(struct sk_buff *skb) | |||
2365 | } | 2368 | } |
2366 | 2369 | ||
2367 | out: | 2370 | out: |
2371 | skb_shinfo(skb)->gso_size = 0; | ||
2368 | __skb_push(skb, -skb_network_offset(skb)); | 2372 | __skb_push(skb, -skb_network_offset(skb)); |
2369 | return netif_receive_skb(skb); | 2373 | return netif_receive_skb(skb); |
2370 | } | 2374 | } |
@@ -2383,7 +2387,7 @@ void napi_gro_flush(struct napi_struct *napi) | |||
2383 | } | 2387 | } |
2384 | EXPORT_SYMBOL(napi_gro_flush); | 2388 | EXPORT_SYMBOL(napi_gro_flush); |
2385 | 2389 | ||
2386 | int napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) | 2390 | static int __napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) |
2387 | { | 2391 | { |
2388 | struct sk_buff **pp = NULL; | 2392 | struct sk_buff **pp = NULL; |
2389 | struct packet_type *ptype; | 2393 | struct packet_type *ptype; |
@@ -2392,6 +2396,7 @@ int napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) | |||
2392 | int count = 0; | 2396 | int count = 0; |
2393 | int same_flow; | 2397 | int same_flow; |
2394 | int mac_len; | 2398 | int mac_len; |
2399 | int free; | ||
2395 | 2400 | ||
2396 | if (!(skb->dev->features & NETIF_F_GRO)) | 2401 | if (!(skb->dev->features & NETIF_F_GRO)) |
2397 | goto normal; | 2402 | goto normal; |
@@ -2408,6 +2413,7 @@ int napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) | |||
2408 | skb->mac_len = mac_len; | 2413 | skb->mac_len = mac_len; |
2409 | NAPI_GRO_CB(skb)->same_flow = 0; | 2414 | NAPI_GRO_CB(skb)->same_flow = 0; |
2410 | NAPI_GRO_CB(skb)->flush = 0; | 2415 | NAPI_GRO_CB(skb)->flush = 0; |
2416 | NAPI_GRO_CB(skb)->free = 0; | ||
2411 | 2417 | ||
2412 | for (p = napi->gro_list; p; p = p->next) { | 2418 | for (p = napi->gro_list; p; p = p->next) { |
2413 | count++; | 2419 | count++; |
@@ -2427,6 +2433,7 @@ int napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) | |||
2427 | goto normal; | 2433 | goto normal; |
2428 | 2434 | ||
2429 | same_flow = NAPI_GRO_CB(skb)->same_flow; | 2435 | same_flow = NAPI_GRO_CB(skb)->same_flow; |
2436 | free = NAPI_GRO_CB(skb)->free; | ||
2430 | 2437 | ||
2431 | if (pp) { | 2438 | if (pp) { |
2432 | struct sk_buff *nskb = *pp; | 2439 | struct sk_buff *nskb = *pp; |
@@ -2446,17 +2453,91 @@ int napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) | |||
2446 | } | 2453 | } |
2447 | 2454 | ||
2448 | NAPI_GRO_CB(skb)->count = 1; | 2455 | NAPI_GRO_CB(skb)->count = 1; |
2456 | skb_shinfo(skb)->gso_size = skb->len; | ||
2449 | skb->next = napi->gro_list; | 2457 | skb->next = napi->gro_list; |
2450 | napi->gro_list = skb; | 2458 | napi->gro_list = skb; |
2451 | 2459 | ||
2452 | ok: | 2460 | ok: |
2453 | return NET_RX_SUCCESS; | 2461 | return free; |
2454 | 2462 | ||
2455 | normal: | 2463 | normal: |
2456 | return netif_receive_skb(skb); | 2464 | return -1; |
2465 | } | ||
2466 | |||
2467 | int napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) | ||
2468 | { | ||
2469 | switch (__napi_gro_receive(napi, skb)) { | ||
2470 | case -1: | ||
2471 | return netif_receive_skb(skb); | ||
2472 | |||
2473 | case 1: | ||
2474 | kfree_skb(skb); | ||
2475 | break; | ||
2476 | } | ||
2477 | |||
2478 | return NET_RX_SUCCESS; | ||
2457 | } | 2479 | } |
2458 | EXPORT_SYMBOL(napi_gro_receive); | 2480 | EXPORT_SYMBOL(napi_gro_receive); |
2459 | 2481 | ||
2482 | int napi_gro_frags(struct napi_struct *napi, struct napi_gro_fraginfo *info) | ||
2483 | { | ||
2484 | struct net_device *dev = napi->dev; | ||
2485 | struct sk_buff *skb = napi->skb; | ||
2486 | int err = NET_RX_DROP; | ||
2487 | |||
2488 | napi->skb = NULL; | ||
2489 | |||
2490 | if (!skb) { | ||
2491 | skb = netdev_alloc_skb(dev, GRO_MAX_HEAD + NET_IP_ALIGN); | ||
2492 | if (!skb) | ||
2493 | goto out; | ||
2494 | |||
2495 | skb_reserve(skb, NET_IP_ALIGN); | ||
2496 | } | ||
2497 | |||
2498 | BUG_ON(info->nr_frags > MAX_SKB_FRAGS); | ||
2499 | skb_shinfo(skb)->nr_frags = info->nr_frags; | ||
2500 | memcpy(skb_shinfo(skb)->frags, info->frags, sizeof(info->frags)); | ||
2501 | |||
2502 | skb->data_len = info->len; | ||
2503 | skb->len += info->len; | ||
2504 | skb->truesize += info->len; | ||
2505 | |||
2506 | if (!pskb_may_pull(skb, ETH_HLEN)) | ||
2507 | goto reuse; | ||
2508 | |||
2509 | err = NET_RX_SUCCESS; | ||
2510 | |||
2511 | skb->protocol = eth_type_trans(skb, dev); | ||
2512 | |||
2513 | skb->ip_summed = info->ip_summed; | ||
2514 | skb->csum = info->csum; | ||
2515 | |||
2516 | switch (__napi_gro_receive(napi, skb)) { | ||
2517 | case -1: | ||
2518 | return netif_receive_skb(skb); | ||
2519 | |||
2520 | case 0: | ||
2521 | goto out; | ||
2522 | } | ||
2523 | |||
2524 | reuse: | ||
2525 | skb_shinfo(skb)->nr_frags = 0; | ||
2526 | |||
2527 | skb->len -= skb->data_len; | ||
2528 | skb->truesize -= skb->data_len; | ||
2529 | skb->data_len = 0; | ||
2530 | |||
2531 | __skb_pull(skb, skb_headlen(skb)); | ||
2532 | skb_reserve(skb, NET_IP_ALIGN - skb_headroom(skb)); | ||
2533 | |||
2534 | napi->skb = skb; | ||
2535 | |||
2536 | out: | ||
2537 | return err; | ||
2538 | } | ||
2539 | EXPORT_SYMBOL(napi_gro_frags); | ||
2540 | |||
2460 | static int process_backlog(struct napi_struct *napi, int quota) | 2541 | static int process_backlog(struct napi_struct *napi, int quota) |
2461 | { | 2542 | { |
2462 | int work = 0; | 2543 | int work = 0; |
@@ -2535,11 +2616,12 @@ void netif_napi_add(struct net_device *dev, struct napi_struct *napi, | |||
2535 | { | 2616 | { |
2536 | INIT_LIST_HEAD(&napi->poll_list); | 2617 | INIT_LIST_HEAD(&napi->poll_list); |
2537 | napi->gro_list = NULL; | 2618 | napi->gro_list = NULL; |
2619 | napi->skb = NULL; | ||
2538 | napi->poll = poll; | 2620 | napi->poll = poll; |
2539 | napi->weight = weight; | 2621 | napi->weight = weight; |
2540 | list_add(&napi->dev_list, &dev->napi_list); | 2622 | list_add(&napi->dev_list, &dev->napi_list); |
2541 | #ifdef CONFIG_NETPOLL | ||
2542 | napi->dev = dev; | 2623 | napi->dev = dev; |
2624 | #ifdef CONFIG_NETPOLL | ||
2543 | spin_lock_init(&napi->poll_lock); | 2625 | spin_lock_init(&napi->poll_lock); |
2544 | napi->poll_owner = -1; | 2626 | napi->poll_owner = -1; |
2545 | #endif | 2627 | #endif |
@@ -2552,6 +2634,7 @@ void netif_napi_del(struct napi_struct *napi) | |||
2552 | struct sk_buff *skb, *next; | 2634 | struct sk_buff *skb, *next; |
2553 | 2635 | ||
2554 | list_del_init(&napi->dev_list); | 2636 | list_del_init(&napi->dev_list); |
2637 | kfree(napi->skb); | ||
2555 | 2638 | ||
2556 | for (skb = napi->gro_list; skb; skb = next) { | 2639 | for (skb = napi->gro_list; skb; skb = next) { |
2557 | next = skb->next; | 2640 | next = skb->next; |