40
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
41
#define rt_dst(rt) (rt->dst)
43
#define rt_dst(rt) (rt->u.dst)
47
41
* ovs_tnl_rcv - ingress point for generic tunnel code
58
52
* - skb->csum does not include the inner Ethernet header.
59
53
* - The layer pointers are undefined.
61
void ovs_tnl_rcv(struct vport *vport, struct sk_buff *skb)
55
void ovs_tnl_rcv(struct vport *vport, struct sk_buff *skb,
56
struct ovs_key_ipv4_tunnel *tun_key)
65
60
skb_reset_mac_header(skb);
68
if (likely(ntohs(eh->h_proto) >= 1536))
63
if (likely(ntohs(eh->h_proto) >= ETH_P_802_3_MIN))
69
64
skb->protocol = eh->h_proto;
71
66
skb->protocol = htons(ETH_P_802_2);
84
ovs_vport_receive(vport, skb);
79
ovs_vport_receive(vport, skb, tun_key);
87
static struct rtable *find_route(struct net *net,
88
__be32 *saddr, __be32 daddr, u8 ipproto,
82
struct rtable *find_route(struct net *net,
83
__be32 *saddr, __be32 daddr, u8 ipproto,
92
87
/* Tunnel configuration keeps DSCP part of TOS bits, But Linux
144
static struct sk_buff *handle_offloads(struct sk_buff *skb,
145
const struct rtable *rt,
139
static struct sk_buff *handle_offloads(struct sk_buff *skb)
151
min_headroom = LL_RESERVED_SPACE(rt_dst(rt).dev) + rt_dst(rt).header_len
153
+ (vlan_tx_tag_present(skb) ? VLAN_HLEN : 0);
155
if (skb_headroom(skb) < min_headroom || skb_header_cloned(skb)) {
156
int head_delta = SKB_DATA_ALIGN(min_headroom -
159
err = pskb_expand_head(skb, max_t(int, head_delta, 0),
165
143
forward_ip_summed(skb, true);
167
145
if (skb_is_gso(skb)) {
168
146
struct sk_buff *nskb;
170
nskb = skb_gso_segment(skb, 0);
147
char cb[sizeof(skb->cb)];
149
memcpy(cb, skb->cb, sizeof(cb));
151
nskb = __skb_gso_segment(skb, 0, false);
171
152
if (IS_ERR(nskb)) {
173
153
err = PTR_ERR(nskb);
177
157
consume_skb(skb);
160
memcpy(nskb->cb, cb, sizeof(cb));
179
163
} else if (get_ip_summed(skb) == OVS_CSUM_PARTIAL) {
180
164
/* Pages aren't locked and could change at any time.
181
165
* If this happens after we compute the checksum, the
185
169
if (unlikely(need_linearize(skb))) {
186
170
err = __skb_linearize(skb);
187
171
if (unlikely(err))
191
175
err = skb_checksum_help(skb);
192
176
if (unlikely(err))
196
180
set_ip_summed(skb, OVS_CSUM_NONE);
203
185
return ERR_PTR(err);
213
195
unsigned int range;
214
u32 hash = OVS_CB(skb)->flow->hash;
196
struct sw_flow_key *pkt_key = OVS_CB(skb)->pkt_key;
197
u32 hash = jhash2((const u32 *)pkt_key,
198
sizeof(*pkt_key) / sizeof(u32), 0);
216
200
inet_get_local_port_range(&low, &high);
217
201
range = (high - low) + 1;
218
202
return (((u64) hash * range) >> 32) + low;
221
int ovs_tnl_send(struct vport *vport, struct sk_buff *skb)
205
int ovs_tnl_send(struct vport *vport, struct sk_buff *skb,
206
u8 ipproto, int tunnel_hlen,
207
void (*build_header)(const struct vport *,
223
struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
224
212
struct rtable *rt;
226
214
int sent_len = 0;
229
if (unlikely(!OVS_CB(skb)->tun_key))
216
struct sk_buff *nskb;
232
218
/* Route lookup */
233
219
saddr = OVS_CB(skb)->tun_key->ipv4_src;
234
220
rt = find_route(ovs_dp_get_net(vport->dp),
236
222
OVS_CB(skb)->tun_key->ipv4_dst,
237
tnl_vport->tnl_ops->ipproto,
238
224
OVS_CB(skb)->tun_key->ipv4_tos,
239
225
skb_get_mark(skb));
231
tunnel_hlen += sizeof(struct iphdr);
233
min_headroom = LL_RESERVED_SPACE(rt_dst(rt).dev) + rt_dst(rt).header_len
235
+ (vlan_tx_tag_present(skb) ? VLAN_HLEN : 0);
237
if (skb_headroom(skb) < min_headroom || skb_header_cloned(skb)) {
238
int head_delta = SKB_DATA_ALIGN(min_headroom -
242
err = pskb_expand_head(skb, max_t(int, head_delta, 0),
244
tunnel_hlen = tnl_vport->tnl_ops->hdr_len(OVS_CB(skb)->tun_key);
245
tunnel_hlen += sizeof(struct iphdr);
247
skb = handle_offloads(skb, rt, tunnel_hlen);
249
nskb = handle_offloads(skb);
250
252
goto err_free_rt;
278
280
skb_dst_set(skb, &rt_dst(rt));
280
282
/* Push Tunnel header. */
281
tnl_vport->tnl_ops->build_header(vport, skb, tunnel_hlen);
283
build_header(vport, skb, tunnel_hlen);
283
285
/* Push IP header. */
284
286
iph = ip_hdr(skb);
285
287
iph->version = 4;
286
288
iph->ihl = sizeof(struct iphdr) >> 2;
287
iph->protocol = tnl_vport->tnl_ops->ipproto;
289
iph->protocol = ipproto;
288
290
iph->daddr = OVS_CB(skb)->tun_key->ipv4_dst;
289
291
iph->saddr = saddr;
290
292
iph->tos = OVS_CB(skb)->tun_key->ipv4_tos;
291
293
iph->ttl = OVS_CB(skb)->tun_key->ipv4_ttl;
292
294
iph->frag_off = OVS_CB(skb)->tun_key->tun_flags &
293
OVS_TNL_F_DONT_FRAGMENT ? htons(IP_DF) : 0;
295
TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
295
297
* Allow our local IP stack to fragment the outer packet even
296
298
* if the DF bit is set as a last resort. We also need to
316
if (unlikely(sent_len == 0))
317
ovs_vport_record_error(vport, VPORT_E_TX_DROPPED);
325
ovs_vport_record_error(vport, VPORT_E_TX_ERROR);
329
struct vport *ovs_tnl_create(const struct vport_parms *parms,
330
const struct vport_ops *vport_ops,
331
const struct tnl_ops *tnl_ops)
334
struct tnl_vport *tnl_vport;
337
vport = ovs_vport_alloc(sizeof(struct tnl_vport), vport_ops, parms);
339
err = PTR_ERR(vport);
343
tnl_vport = tnl_vport_priv(vport);
345
strcpy(tnl_vport->name, parms->name);
346
tnl_vport->tnl_ops = tnl_ops;
354
static void free_port_rcu(struct rcu_head *rcu)
356
struct tnl_vport *tnl_vport = container_of(rcu,
357
struct tnl_vport, rcu);
359
ovs_vport_free(vport_from_priv(tnl_vport));
362
void ovs_tnl_destroy(struct vport *vport)
364
struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
366
call_rcu(&tnl_vport->rcu, free_port_rcu);
369
const char *ovs_tnl_get_name(const struct vport *vport)
371
const struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
372
return tnl_vport->name;