2 * Copyright (c) 2014 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "packet-dpif.h"
23 dpif_packet_new_with_headroom(size_t size, size_t headroom)
25 struct dpif_packet *p = xmalloc(sizeof *p);
26 struct ofpbuf *b = &p->ofpbuf;
28 ofpbuf_init(b, size + headroom);
29 ofpbuf_reserve(b, headroom);
35 dpif_packet_clone_from_ofpbuf(const struct ofpbuf *b)
37 struct dpif_packet *p = xmalloc(sizeof *p);
38 size_t headroom = ofpbuf_headroom(b);
40 ofpbuf_init(&p->ofpbuf, ofpbuf_size(b) + headroom);
41 ofpbuf_reserve(&p->ofpbuf, headroom);
43 ofpbuf_put(&p->ofpbuf, ofpbuf_data(b), ofpbuf_size(b));
47 = (char *)ofpbuf_data(&p->ofpbuf) - (char *)ofpbuf_data(b);
49 p->ofpbuf.frame = (char *) b->frame + data_delta;
51 p->ofpbuf.l2_5_ofs = b->l2_5_ofs;
52 p->ofpbuf.l3_ofs = b->l3_ofs;
53 p->ofpbuf.l4_ofs = b->l4_ofs;
59 dpif_packet_clone(struct dpif_packet *p)
61 struct dpif_packet *newp;
63 newp = dpif_packet_clone_from_ofpbuf(&p->ofpbuf);
65 dpif_packet_set_dp_hash(newp, dpif_packet_get_dp_hash(p));