Don't call kfree_skb() with interrupts disabled.
[sliver-openvswitch.git] / datapath / forward.c
1 /*
2  * Distributed under the terms of the GNU GPL version 2.
3  * Copyright (c) 2007, 2008 The Board of Trustees of The Leland 
4  * Stanford Junior University
5  */
6
7 #include <linux/if_ether.h>
8 #include <linux/if_vlan.h>
9 #include <linux/in.h>
10 #include <linux/ip.h>
11 #include <linux/tcp.h>
12 #include <linux/udp.h>
13 #include <linux/in6.h>
14 #include <asm/uaccess.h>
15 #include <linux/types.h>
16 #include <net/checksum.h>
17 #include "forward.h"
18 #include "datapath.h"
19 #include "chain.h"
20 #include "flow.h"
21
22 /* FIXME: do we need to use GFP_ATOMIC everywhere here? */
23
24 static int make_writable(struct sk_buff **);
25
26 static struct sk_buff *retrieve_skb(uint32_t id);
27 static void discard_skb(uint32_t id);
28
29 /* 'skb' was received on 'in_port', a physical switch port between 0 and
30  * OFPP_MAX.  Process it according to 'chain'.  Returns 0 if successful, in
31  * which case 'skb' is destroyed, or -ESRCH if there is no matching flow, in
32  * which case 'skb' still belongs to the caller. */
33 int run_flow_through_tables(struct sw_chain *chain, struct sk_buff *skb,
34                             int in_port)
35 {
36         struct sw_flow_key key;
37         struct sw_flow *flow;
38
39         if (flow_extract(skb, in_port, &key)
40             && (chain->dp->flags & OFPC_FRAG_MASK) == OFPC_FRAG_DROP) {
41                 /* Drop fragment. */
42                 kfree_skb(skb);
43                 return 0;
44         }
45
46         flow = chain_lookup(chain, &key);
47         if (likely(flow != NULL)) {
48                 flow_used(flow, skb);
49                 execute_actions(chain->dp, skb, &key,
50                                 flow->actions, flow->n_actions);
51                 return 0;
52         } else {
53                 return -ESRCH;
54         }
55 }
56
57 /* 'skb' was received on 'in_port', a physical switch port between 0 and
58  * OFPP_MAX.  Process it according to 'chain', sending it up to the controller
59  * if no flow matches.  Takes ownership of 'skb'. */
60 void fwd_port_input(struct sw_chain *chain, struct sk_buff *skb, int in_port)
61 {
62         if (run_flow_through_tables(chain, skb, in_port))
63                 dp_output_control(chain->dp, skb, fwd_save_skb(skb), 
64                                   chain->dp->miss_send_len,
65                                   OFPR_NO_MATCH);
66 }
67
68 static int do_output(struct datapath *dp, struct sk_buff *skb, size_t max_len,
69                         int out_port)
70 {
71         if (!skb)
72                 return -ENOMEM;
73         return (likely(out_port != OFPP_CONTROLLER)
74                 ? dp_output_port(dp, skb, out_port)
75                 : dp_output_control(dp, skb, fwd_save_skb(skb),
76                                          max_len, OFPR_ACTION));
77 }
78
79 void execute_actions(struct datapath *dp, struct sk_buff *skb,
80                                 const struct sw_flow_key *key,
81                                 const struct ofp_action *actions, int n_actions)
82 {
83         /* Every output action needs a separate clone of 'skb', but the common
84          * case is just a single output action, so that doing a clone and
85          * then freeing the original skbuff is wasteful.  So the following code
86          * is slightly obscure just to avoid that. */
87         int prev_port;
88         size_t max_len=0;        /* Initialze to make compiler happy */
89         uint16_t eth_proto;
90         int i;
91
92         prev_port = -1;
93         eth_proto = ntohs(key->dl_type);
94
95         for (i = 0; i < n_actions; i++) {
96                 const struct ofp_action *a = &actions[i];
97
98                 if (prev_port != -1) {
99                         do_output(dp, skb_clone(skb, GFP_ATOMIC),
100                                   max_len, prev_port);
101                         prev_port = -1;
102                 }
103
104                 if (likely(a->type == htons(OFPAT_OUTPUT))) {
105                         prev_port = ntohs(a->arg.output.port);
106                         max_len = ntohs(a->arg.output.max_len);
107                 } else {
108                         if (!make_writable(&skb)) {
109                                 if (net_ratelimit())
110                                     printk("make_writable failed\n");
111                                 break;
112                         }
113                         skb = execute_setter(skb, eth_proto, key, a);
114                         if (!skb) {
115                                 if (net_ratelimit())
116                                         printk("execute_setter lost skb\n");
117                                 return;
118                         }
119                 }
120         }
121         if (prev_port != -1)
122                 do_output(dp, skb, max_len, prev_port);
123         else
124                 kfree_skb(skb);
125 }
126
127 /* Updates 'sum', which is a field in 'skb''s data, given that a 4-byte field
128  * covered by the sum has been changed from 'from' to 'to'.  If set,
129  * 'pseudohdr' indicates that the field is in the TCP or UDP pseudo-header.
130  * Based on nf_proto_csum_replace4. */
131 static void update_csum(__sum16 *sum, struct sk_buff *skb,
132                         __be32 from, __be32 to, int pseudohdr)
133 {
134         __be32 diff[] = { ~from, to };
135         if (skb->ip_summed != CHECKSUM_PARTIAL) {
136                 *sum = csum_fold(csum_partial((char *)diff, sizeof(diff),
137                                 ~csum_unfold(*sum)));
138                 if (skb->ip_summed == CHECKSUM_COMPLETE && pseudohdr)
139                         skb->csum = ~csum_partial((char *)diff, sizeof(diff),
140                                                 ~skb->csum);
141         } else if (pseudohdr)
142                 *sum = ~csum_fold(csum_partial((char *)diff, sizeof(diff),
143                                 csum_unfold(*sum)));
144 }
145
146 static void modify_nh(struct sk_buff *skb, uint16_t eth_proto,
147                         uint8_t nw_proto, const struct ofp_action *a)
148 {
149         if (eth_proto == ETH_P_IP) {
150                 struct iphdr *nh = ip_hdr(skb);
151                 uint32_t new, *field;
152
153                 new = a->arg.nw_addr;
154
155                 if (a->type == htons(OFPAT_SET_NW_SRC))
156                         field = &nh->saddr;
157                 else
158                         field = &nh->daddr;
159
160                 if (nw_proto == IPPROTO_TCP) {
161                         struct tcphdr *th = tcp_hdr(skb);
162                         update_csum(&th->check, skb, *field, new, 1);
163                 } else if (nw_proto == IPPROTO_UDP) {
164                         struct udphdr *th = udp_hdr(skb);
165                         update_csum(&th->check, skb, *field, new, 1);
166                 }
167                 update_csum(&nh->check, skb, *field, new, 0);
168                 *field = new;
169         }
170 }
171
172 static void modify_th(struct sk_buff *skb, uint16_t eth_proto,
173                         uint8_t nw_proto, const struct ofp_action *a)
174 {
175         if (eth_proto == ETH_P_IP) {
176                 uint16_t new, *field;
177
178                 new = a->arg.tp;
179
180                 if (nw_proto == IPPROTO_TCP) {
181                         struct tcphdr *th = tcp_hdr(skb);
182
183                         if (a->type == htons(OFPAT_SET_TP_SRC))
184                                 field = &th->source;
185                         else
186                                 field = &th->dest;
187
188                         update_csum(&th->check, skb, *field, new, 1);
189                         *field = new;
190                 } else if (nw_proto == IPPROTO_UDP) {
191                         struct udphdr *th = udp_hdr(skb);
192
193                         if (a->type == htons(OFPAT_SET_TP_SRC))
194                                 field = &th->source;
195                         else
196                                 field = &th->dest;
197
198                         update_csum(&th->check, skb, *field, new, 1);
199                         *field = new;
200                 }
201         }
202 }
203
204 static struct sk_buff *vlan_pull_tag(struct sk_buff *skb)
205 {
206         struct vlan_ethhdr *vh = vlan_eth_hdr(skb);
207         struct ethhdr *eh;
208
209
210         /* Verify we were given a vlan packet */
211         if (vh->h_vlan_proto != htons(ETH_P_8021Q))
212                 return skb;
213
214         memmove(skb->data + VLAN_HLEN, skb->data, 2 * VLAN_ETH_ALEN);
215
216         eh = (struct ethhdr *)skb_pull(skb, VLAN_HLEN);
217
218         skb->protocol = eh->h_proto;
219         skb->mac_header += VLAN_HLEN;
220
221         return skb;
222 }
223
224 static struct sk_buff *modify_vlan(struct sk_buff *skb, 
225                 const struct sw_flow_key *key, const struct ofp_action *a)
226 {
227         uint16_t new_id = ntohs(a->arg.vlan_id);
228
229         if (new_id != OFP_VLAN_NONE) {
230                 if (key->dl_vlan != htons(OFP_VLAN_NONE)) {
231                         /* Modify vlan id, but maintain other TCI values */
232                         struct vlan_ethhdr *vh = vlan_eth_hdr(skb);
233                         vh->h_vlan_TCI = (vh->h_vlan_TCI 
234                                         & ~(htons(VLAN_VID_MASK))) | a->arg.vlan_id;
235                 } else  {
236                         /* Add vlan header */
237
238                         /* xxx The vlan_put_tag function, doesn't seem to work
239                          * xxx reliably when it attempts to use the hardware-accelerated
240                          * xxx version.  We'll directly use the software version
241                          * xxx until the problem can be diagnosed.
242                          */
243                         skb = __vlan_put_tag(skb, new_id);
244                 }
245         } else  {
246                 /* Remove an existing vlan header if it exists */
247                 vlan_pull_tag(skb);
248         }
249
250         return skb;
251 }
252
253 struct sk_buff *execute_setter(struct sk_buff *skb, uint16_t eth_proto,
254                         const struct sw_flow_key *key, const struct ofp_action *a)
255 {
256         switch (ntohs(a->type)) {
257         case OFPAT_SET_DL_VLAN:
258                 skb = modify_vlan(skb, key, a);
259                 break;
260
261         case OFPAT_SET_DL_SRC: {
262                 struct ethhdr *eh = eth_hdr(skb);
263                 memcpy(eh->h_source, a->arg.dl_addr, sizeof eh->h_source);
264                 break;
265         }
266         case OFPAT_SET_DL_DST: {
267                 struct ethhdr *eh = eth_hdr(skb);
268                 memcpy(eh->h_dest, a->arg.dl_addr, sizeof eh->h_dest);
269                 break;
270         }
271
272         case OFPAT_SET_NW_SRC:
273         case OFPAT_SET_NW_DST:
274                 modify_nh(skb, eth_proto, key->nw_proto, a);
275                 break;
276
277         case OFPAT_SET_TP_SRC:
278         case OFPAT_SET_TP_DST:
279                 modify_th(skb, eth_proto, key->nw_proto, a);
280                 break;
281         
282         default:
283                 if (net_ratelimit())
284                         printk("execute_setter: unknown action: %d\n", ntohs(a->type));
285         }
286
287         return skb;
288 }
289
290 static int
291 recv_features_request(struct sw_chain *chain, const struct sender *sender,
292                       const void *msg) 
293 {
294         return dp_send_features_reply(chain->dp, sender);
295 }
296
297 static int
298 recv_get_config_request(struct sw_chain *chain, const struct sender *sender,
299                         const void *msg)
300 {
301         return dp_send_config_reply(chain->dp, sender);
302 }
303
304 static int
305 recv_set_config(struct sw_chain *chain, const struct sender *sender,
306                 const void *msg)
307 {
308         const struct ofp_switch_config *osc = msg;
309         int flags;
310
311         flags = ntohs(osc->flags) & ~(OFPC_SEND_FLOW_EXP | OFPC_FRAG_MASK);
312         if ((flags & OFPC_FRAG_MASK) != OFPC_FRAG_NORMAL
313             && (flags & OFPC_FRAG_MASK) != OFPC_FRAG_DROP) {
314                 flags = (flags & ~OFPC_FRAG_MASK) | OFPC_FRAG_DROP;
315         }
316         chain->dp->flags = flags;
317
318         chain->dp->miss_send_len = ntohs(osc->miss_send_len);
319
320         return 0;
321 }
322
323 static int
324 recv_packet_out(struct sw_chain *chain, const struct sender *sender,
325                 const void *msg)
326 {
327         const struct ofp_packet_out *opo = msg;
328         struct sk_buff *skb;
329         struct vlan_ethhdr *mac;
330         int nh_ofs;
331
332         if (ntohl(opo->buffer_id) == (uint32_t) -1) {
333                 int data_len = ntohs(opo->header.length) - sizeof *opo;
334
335                 /* FIXME: there is likely a way to reuse the data in msg. */
336                 skb = alloc_skb(data_len, GFP_ATOMIC);
337                 if (!skb)
338                         return -ENOMEM;
339
340                 /* FIXME?  We don't reserve NET_IP_ALIGN or NET_SKB_PAD since
341                  * we're just transmitting this raw without examining anything
342                  * at those layers. */
343                 memcpy(skb_put(skb, data_len), opo->u.data, data_len);
344                 dp_set_origin(chain->dp, ntohs(opo->in_port), skb);
345
346                 skb_set_mac_header(skb, 0);
347                 mac = vlan_eth_hdr(skb);
348                 if (likely(mac->h_vlan_proto != htons(ETH_P_8021Q)))
349                         nh_ofs = sizeof(struct ethhdr);
350                 else
351                         nh_ofs = sizeof(struct vlan_ethhdr);
352                 skb_set_network_header(skb, nh_ofs);
353
354                 dp_output_port(chain->dp, skb, ntohs(opo->out_port));
355         } else {
356                 struct sw_flow_key key;
357                 int n_acts;
358
359                 skb = retrieve_skb(ntohl(opo->buffer_id));
360                 if (!skb)
361                         return -ESRCH;
362                 dp_set_origin(chain->dp, ntohs(opo->in_port), skb);
363
364                 n_acts = (ntohs(opo->header.length) - sizeof *opo) 
365                                 / sizeof *opo->u.actions;
366                 flow_extract(skb, ntohs(opo->in_port), &key);
367                 execute_actions(chain->dp, skb, &key, opo->u.actions, n_acts);
368         }
369         return 0;
370 }
371
372 static int
373 recv_port_mod(struct sw_chain *chain, const struct sender *sender,
374               const void *msg)
375 {
376         const struct ofp_port_mod *opm = msg;
377
378         dp_update_port_flags(chain->dp, &opm->desc);
379
380         return 0;
381 }
382
383 static int
384 recv_echo_request(struct sw_chain *chain, const struct sender *sender,
385                   const void *msg) 
386 {
387         return dp_send_echo_reply(chain->dp, sender, msg);
388 }
389
390 static int
391 recv_echo_reply(struct sw_chain *chain, const struct sender *sender,
392                   const void *msg) 
393 {
394         return 0;
395 }
396
397 static int
398 add_flow(struct sw_chain *chain, const struct ofp_flow_mod *ofm)
399 {
400         int error = -ENOMEM;
401         int i;
402         int n_acts;
403         struct sw_flow *flow;
404
405
406         /* To prevent loops, make sure there's no action to send to the
407          * OFP_TABLE virtual port.
408          */
409         n_acts = (ntohs(ofm->header.length) - sizeof *ofm) / sizeof *ofm->actions;
410         for (i=0; i<n_acts; i++) {
411                 const struct ofp_action *a = &ofm->actions[i];
412
413                 if (a->type == htons(OFPAT_OUTPUT) 
414                                         && (a->arg.output.port == htons(OFPP_TABLE) 
415                                                 || a->arg.output.port == htons(OFPP_NONE))) {
416                         /* xxx Send fancy new error message? */
417                         goto error;
418                 }
419         }
420
421         /* Allocate memory. */
422         flow = flow_alloc(n_acts, GFP_ATOMIC);
423         if (flow == NULL)
424                 goto error;
425
426         /* Fill out flow. */
427         flow_extract_match(&flow->key, &ofm->match);
428         flow->max_idle = ntohs(ofm->max_idle);
429         flow->priority = flow->key.wildcards ? ntohs(ofm->priority) : -1;
430         flow->timeout = jiffies + flow->max_idle * HZ;
431         flow->n_actions = n_acts;
432         flow->init_time = jiffies;
433         flow->byte_count = 0;
434         flow->packet_count = 0;
435         spin_lock_init(&flow->lock);
436         memcpy(flow->actions, ofm->actions, n_acts * sizeof *flow->actions);
437
438         /* Act. */
439         error = chain_insert(chain, flow);
440         if (error)
441                 goto error_free_flow;
442         error = 0;
443         if (ntohl(ofm->buffer_id) != (uint32_t) -1) {
444                 struct sk_buff *skb = retrieve_skb(ntohl(ofm->buffer_id));
445                 if (skb) {
446                         struct sw_flow_key key;
447                         flow_used(flow, skb);
448                         flow_extract(skb, ntohs(ofm->match.in_port), &key);
449                         execute_actions(chain->dp, skb, &key,
450                                         ofm->actions, n_acts);
451                 }
452                 else
453                         error = -ESRCH;
454         }
455         return error;
456
457 error_free_flow:
458         flow_free(flow);
459 error:
460         if (ntohl(ofm->buffer_id) != (uint32_t) -1)
461                 discard_skb(ntohl(ofm->buffer_id));
462         return error;
463 }
464
465 static int
466 recv_flow(struct sw_chain *chain, const struct sender *sender, const void *msg)
467 {
468         const struct ofp_flow_mod *ofm = msg;
469         uint16_t command = ntohs(ofm->command);
470
471         if (command == OFPFC_ADD) {
472                 return add_flow(chain, ofm);
473         }  else if (command == OFPFC_DELETE) {
474                 struct sw_flow_key key;
475                 flow_extract_match(&key, &ofm->match);
476                 return chain_delete(chain, &key, 0, 0) ? 0 : -ESRCH;
477         } else if (command == OFPFC_DELETE_STRICT) {
478                 struct sw_flow_key key;
479                 uint16_t priority;
480                 flow_extract_match(&key, &ofm->match);
481                 priority = key.wildcards ? ntohs(ofm->priority) : -1;
482                 return chain_delete(chain, &key, priority, 1) ? 0 : -ESRCH;
483         } else {
484                 return -ENOTSUPP;
485         }
486 }
487
488 /* 'msg', which is 'length' bytes long, was received across Netlink from
489  * 'sender'.  Apply it to 'chain'. */
490 int
491 fwd_control_input(struct sw_chain *chain, const struct sender *sender,
492                   const void *msg, size_t length)
493 {
494
495         struct openflow_packet {
496                 size_t min_size;
497                 int (*handler)(struct sw_chain *, const struct sender *,
498                                const void *);
499         };
500
501         static const struct openflow_packet packets[] = {
502                 [OFPT_FEATURES_REQUEST] = {
503                         sizeof (struct ofp_header),
504                         recv_features_request,
505                 },
506                 [OFPT_GET_CONFIG_REQUEST] = {
507                         sizeof (struct ofp_header),
508                         recv_get_config_request,
509                 },
510                 [OFPT_SET_CONFIG] = {
511                         sizeof (struct ofp_switch_config),
512                         recv_set_config,
513                 },
514                 [OFPT_PACKET_OUT] = {
515                         sizeof (struct ofp_packet_out),
516                         recv_packet_out,
517                 },
518                 [OFPT_FLOW_MOD] = {
519                         sizeof (struct ofp_flow_mod),
520                         recv_flow,
521                 },
522                 [OFPT_PORT_MOD] = {
523                         sizeof (struct ofp_port_mod),
524                         recv_port_mod,
525                 },
526                 [OFPT_ECHO_REQUEST] = {
527                         sizeof (struct ofp_header),
528                         recv_echo_request,
529                 },
530                 [OFPT_ECHO_REPLY] = {
531                         sizeof (struct ofp_header),
532                         recv_echo_reply,
533                 },
534         };
535
536         const struct openflow_packet *pkt;
537         struct ofp_header *oh;
538
539         oh = (struct ofp_header *) msg;
540         if (oh->version != OFP_VERSION || oh->type >= ARRAY_SIZE(packets)
541                 || ntohs(oh->length) > length)
542                 return -EINVAL;
543
544         pkt = &packets[oh->type];
545         if (!pkt->handler)
546                 return -ENOSYS;
547         if (length < pkt->min_size)
548                 return -EFAULT;
549
550         return pkt->handler(chain, sender, msg);
551 }
552
553 /* Packet buffering. */
554
555 #define OVERWRITE_SECS  1
556 #define OVERWRITE_JIFFIES (OVERWRITE_SECS * HZ)
557
558 struct packet_buffer {
559         struct sk_buff *skb;
560         uint32_t cookie;
561         unsigned long exp_jiffies;
562 };
563
564 static struct packet_buffer buffers[N_PKT_BUFFERS];
565 static unsigned int buffer_idx;
566 static DEFINE_SPINLOCK(buffer_lock);
567
568 uint32_t fwd_save_skb(struct sk_buff *skb)
569 {
570         struct sk_buff *old_skb = NULL;
571         struct packet_buffer *p;
572         unsigned long int flags;
573         uint32_t id;
574
575         spin_lock_irqsave(&buffer_lock, flags);
576         buffer_idx = (buffer_idx + 1) & PKT_BUFFER_MASK;
577         p = &buffers[buffer_idx];
578         if (p->skb) {
579                 /* Don't buffer packet if existing entry is less than
580                  * OVERWRITE_SECS old. */
581                 if (time_before(jiffies, p->exp_jiffies)) {
582                         spin_unlock_irqrestore(&buffer_lock, flags);
583                         return -1;
584                 } else {
585                         /* Defer kfree_skb() until interrupts re-enabled. */
586                         old_skb = p->skb;
587                 }
588         }
589         /* Don't use maximum cookie value since the all-bits-1 id is
590          * special. */
591         if (++p->cookie >= (1u << PKT_COOKIE_BITS) - 1)
592                 p->cookie = 0;
593         skb_get(skb);
594         p->skb = skb;
595         p->exp_jiffies = jiffies + OVERWRITE_JIFFIES;
596         id = buffer_idx | (p->cookie << PKT_BUFFER_BITS);
597         spin_unlock_irqrestore(&buffer_lock, flags);
598
599         if (old_skb)
600                 kfree_skb(old_skb);
601
602         return id;
603 }
604
605 static struct sk_buff *retrieve_skb(uint32_t id)
606 {
607         unsigned long int flags;
608         struct sk_buff *skb = NULL;
609         struct packet_buffer *p;
610
611         spin_lock_irqsave(&buffer_lock, flags);
612         p = &buffers[id & PKT_BUFFER_MASK];
613         if (p->cookie == id >> PKT_BUFFER_BITS) {
614                 skb = p->skb;
615                 p->skb = NULL;
616         } else {
617                 printk("cookie mismatch: %x != %x\n",
618                                 id >> PKT_BUFFER_BITS, p->cookie);
619         }
620         spin_unlock_irqrestore(&buffer_lock, flags);
621
622         return skb;
623 }
624
625 void fwd_discard_all(void) 
626 {
627         int i;
628
629         for (i = 0; i < N_PKT_BUFFERS; i++) {
630                 struct sk_buff *skb;
631                 unsigned long int flags;
632
633                 /* Defer kfree_skb() until interrupts re-enabled. */
634                 spin_lock_irqsave(&buffer_lock, flags);
635                 skb = buffers[i].skb;
636                 buffers[i].skb = NULL;
637                 spin_unlock_irqrestore(&buffer_lock, flags);
638
639                 kfree_skb(skb);
640         }
641 }
642
643 static void discard_skb(uint32_t id)
644 {
645         struct sk_buff *old_skb = NULL;
646         unsigned long int flags;
647         struct packet_buffer *p;
648
649         spin_lock_irqsave(&buffer_lock, flags);
650         p = &buffers[id & PKT_BUFFER_MASK];
651         if (p->cookie == id >> PKT_BUFFER_BITS) {
652                 /* Defer kfree_skb() until interrupts re-enabled. */
653                 old_skb = p->skb;
654                 p->skb = NULL;
655         }
656         spin_unlock_irqrestore(&buffer_lock, flags);
657
658         if (old_skb)
659                 kfree_skb(old_skb);
660 }
661
662 void fwd_exit(void)
663 {
664         fwd_discard_all();
665 }
666
667 /* Utility functions. */
668
669 /* Makes '*pskb' writable, possibly copying it and setting '*pskb' to point to
670  * the copy.
671  * Returns 1 if successful, 0 on failure. */
672 static int
673 make_writable(struct sk_buff **pskb)
674 {
675         /* Based on skb_make_writable() in net/netfilter/core.c. */
676         struct sk_buff *nskb;
677
678         /* Not exclusive use of packet?  Must copy. */
679         if (skb_shared(*pskb) || skb_cloned(*pskb))
680                 goto copy_skb;
681
682         return pskb_may_pull(*pskb, 40); /* FIXME? */
683
684 copy_skb:
685         nskb = skb_copy(*pskb, GFP_ATOMIC);
686         if (!nskb)
687                 return 0;
688         BUG_ON(skb_is_nonlinear(nskb));
689
690         /* Rest of kernel will get very unhappy if we pass it a
691            suddenly-orphaned skbuff */
692         if ((*pskb)->sk)
693                 skb_set_owner_w(nskb, (*pskb)->sk);
694         kfree_skb(*pskb);
695         *pskb = nskb;
696         return 1;
697 }