-
Notifications
You must be signed in to change notification settings - Fork 16
/
0003-Add-userspace-dataplane-nsh-support-and-remove-push_.patch
2327 lines (2191 loc) · 91.4 KB
/
0003-Add-userspace-dataplane-nsh-support-and-remove-push_.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 2128cb639419c95b86da3fd0302b8fcf329f45ab Mon Sep 17 00:00:00 2001
From: Yi Yang <[email protected]>
Date: Wed, 13 Apr 2016 16:39:27 +0800
Subject: [PATCH 3/8] Add userspace dataplane nsh support and remove push_eth
and pop_eth actions
Signed-off-by: Mengke Liu <[email protected]>
Signed-off-by: Ricky Li <[email protected]>
Signed-off-by: Johnson Li <[email protected]>
Signed-off-by: Yi Yang <[email protected]>
---
datapath/actions.c | 53 +---
datapath/flow.c | 50 ++--
datapath/flow.h | 16 +-
datapath/flow_netlink.c | 44 +--
datapath/linux/compat/include/linux/openvswitch.h | 112 ++++++--
datapath/linux/compat/include/net/vxlan.h | 9 +-
datapath/linux/compat/vxlan.c | 15 ++
lib/dpif-netdev.c | 30 ++-
lib/dpif.c | 2 -
lib/flow.c | 99 ++++++-
lib/flow.h | 14 +-
lib/match.c | 13 +-
lib/match.h | 2 +-
lib/meta-flow.h | 2 +-
lib/netdev-vport.c | 76 +++++-
lib/netdev-vport.h | 6 +
lib/nx-match.c | 3 +-
lib/odp-execute.c | 23 +-
lib/odp-util.c | 314 ++++++----------------
lib/odp-util.h | 6 +-
lib/ofp-actions.c | 82 +-----
lib/ofp-actions.h | 2 -
lib/packets.c | 23 ++
lib/packets.h | 3 +
ofproto/ofproto-dpif-sflow.c | 1 -
ofproto/ofproto-dpif-upcall.c | 8 -
ofproto/ofproto-dpif-xlate.c | 13 +-
ofproto/ofproto-dpif.h | 1 -
ofproto/tunnel.c | 1 +
tests/ofproto.at | 1 -
tests/tunnel.at | 189 +++++++++++--
31 files changed, 666 insertions(+), 547 deletions(-)
diff --git a/datapath/actions.c b/datapath/actions.c
index 16fc58f..7072638 100644
--- a/datapath/actions.c
+++ b/datapath/actions.c
@@ -254,10 +254,10 @@ static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
static int pop_nsh(struct sk_buff *skb, struct sw_flow_key *key)
{
- if (!pskb_may_pull(skb, NSH_M_TYPE1_LEN))
+ if (!pskb_may_pull(skb, ETH_NSH_TYPE1_HEADER_SIZE))
return -ENOMEM;
else
- __skb_pull(skb, NSH_M_TYPE1_LEN);
+ __skb_pull(skb, ETH_NSH_TYPE1_HEADER_SIZE);
return 0;
}
@@ -267,48 +267,21 @@ static int push_nsh(struct sk_buff *skb, struct sw_flow_key *key,
{
if (nsh->nsh_mdtype == NSH_M_TYPE1) {
- if (skb_cow_head(skb, NSH_M_TYPE1_LEN) < 0)
- return -ENOMEM;
-
- skb_push(skb, NSH_M_TYPE1_LEN);
- OVS_CB(skb)->nsh_header = skb->data;
- memcpy(OVS_CB(skb)->nsh_header, nsh->header, NSH_M_TYPE1_LEN);
- }
- else
- return -EINVAL;
-
- return 0;
-}
-
-static int pop_eth(struct sk_buff *skb, struct sw_flow_key *key)
-{
- if (!pskb_may_pull(skb, ENCAP_ETH_PUSH_HEADER_SIZE))
- return -ENOMEM;
- else
- __skb_pull(skb, ENCAP_ETH_PUSH_HEADER_SIZE);
-
- return 0;
-}
-
-static int push_eth(struct sk_buff *skb, struct sw_flow_key *key,
- const struct ovs_action_push_eth *encap_eth)
-{
- if (encap_eth->encap_eth_type == htons(ETH_P_NSH)) {
- if (skb_cow_head(skb, ENCAP_ETH_PUSH_HEADER_SIZE) < 0)
+ if (skb_cow_head(skb, ETH_NSH_TYPE1_HEADER_SIZE) < 0) {
return -ENOMEM;
+ }
- skb_push(skb, ENCAP_ETH_PUSH_HEADER_SIZE);
- OVS_CB(skb)->encap_eth_header = skb->data;
- memcpy(OVS_CB(skb)->encap_eth_header, encap_eth->header, ENCAP_ETH_PUSH_HEADER_SIZE);
+ skb_push(skb, ETH_NSH_TYPE1_HEADER_SIZE);
+ OVS_CB(skb)->encap_eth_header = (struct encap_eth_hdr *)skb->data;
+ OVS_CB(skb)->nsh_header = (struct nsh_hdr *)(skb->data + ENCAP_ETH_LEN);
+ memcpy(skb->data, nsh->header, ETH_NSH_TYPE1_HEADER_SIZE);
}
- else {
+ else
return -EINVAL;
- }
return 0;
}
-
/* 'src' is already properly masked. */
static void ether_addr_copy_masked(u8 *dst_, const u8 *src_, const u8 *mask_)
{
@@ -1144,14 +1117,6 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
err = pop_nsh(skb, key);
break;
- case OVS_ACTION_ATTR_PUSH_ETH:
- err = push_eth(skb, key, nla_data(a));
- break;
-
- case OVS_ACTION_ATTR_POP_ETH:
- err = pop_eth(skb, key);
- break;
-
case OVS_ACTION_ATTR_RECIRC:
err = execute_recirc(dp, skb, key, a, rem);
if (nla_is_last(a, rem)) {
diff --git a/datapath/flow.c b/datapath/flow.c
index 67b2f1d..e3f33f8 100644
--- a/datapath/flow.c
+++ b/datapath/flow.c
@@ -320,8 +320,12 @@ static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
}
static int parse_nsh(struct sk_buff *skb, struct sw_flow_key *key){
- struct nsh_hdr *nsh_hdr = (struct nsh_hdr *)skb->data;
+ struct nsh_hdr *nsh_hdr = NULL;
+
+ OVS_CB(skb)->encap_eth_header = (struct encap_eth_hdr *)skb->data;
+ nsh_hdr = (struct nsh_hdr *)((const char *)skb->data + ENCAP_ETH_LEN);
OVS_CB(skb)->nsh_header = nsh_hdr;
+ memcpy(&key->nsh.encap_eth_dst, skb->data, ENCAP_ETH_LEN);
key->nsh.nsh_mdtype = nsh_hdr->base.mdtype;
if (key->nsh.nsh_mdtype != NSH_M_TYPE1)
return -EPERM;
@@ -335,16 +339,6 @@ static int parse_nsh(struct sk_buff *skb, struct sw_flow_key *key){
return 0;
}
-static void parse_encap_eth(struct sk_buff *skb, struct sw_flow_key *key){
- struct encap_eth_hdr *encap_eth_header = (struct encap_eth_hdr *)skb->data;
- OVS_CB(skb)->encap_eth_header = encap_eth_header;
- key->encap_eth.encap_eth_type = encap_eth_header->encap_eth_type;
- ether_addr_copy(key->encap_eth.encap_eth_src, encap_eth_header->encap_eth_src);
- ether_addr_copy(key->encap_eth.encap_eth_dst, encap_eth_header->encap_eth_dst);
-
- return;
-}
-
static __be16 parse_ethertype(struct sk_buff *skb)
{
struct llc_snap_hdr {
@@ -483,23 +477,21 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
{
int error;
struct ethhdr *eth;
+ int is_eth_nsh = 0;
/* Extract ethernet+nsh if ethernet type is 0x894F */
eth = (struct ethhdr *)skb->data;
if (eth->h_proto == htons(ETH_P_NSH)) {
- parse_encap_eth(skb, key);
- __skb_pull(skb, ENCAP_ETH_LEN);
-
if (unlikely(parse_nsh(skb, key)))
return -EINVAL;
if (key->nsh.nsh_mdtype == NSH_M_TYPE1 && key->nsh.nsh_np == NSH_P_ETHERNET) {
- __skb_pull(skb, NSH_M_TYPE1_LEN);
+ __skb_pull(skb, ENCAP_ETH_LEN + NSH_M_TYPE1_LEN);
+ is_eth_nsh = 1;
} else {
return -EINVAL;
}
} else {
- void *encap_eth_hdr = &(key->encap_eth);
- memset(encap_eth_hdr, 0, ENCAP_ETH_LEN);
+ memset(&key->nsh, 0, sizeof(key->nsh));
}
/* Flags are always used as part of stats */
@@ -722,15 +714,15 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
}
}
- if (key->encap_eth.encap_eth_type == htons(ETH_P_NSH))
+ if (is_eth_nsh == 1) {
__skb_push(skb, ENCAP_ETH_LEN + NSH_M_TYPE1_LEN);
+ }
return 0;
}
-static void ovs_key_nsh_init(struct sw_flow_key *key, __u16 len) {
- void *nsh_hdr = &(key->nsh);
- memset(nsh_hdr, 0, len);
+static void ovs_key_nsh_init(struct sw_flow_key *key) {
+ memset(&key->nsh, 0, sizeof(key->nsh));
}
static int nsh_extract(struct sk_buff *skb, struct sw_flow_key *key) {
@@ -740,16 +732,16 @@ static int nsh_extract(struct sk_buff *skb, struct sw_flow_key *key) {
if (unlikely(parse_nsh(skb, key)))
return -EINVAL;
if (key->nsh.nsh_mdtype == NSH_M_TYPE1) {
- __skb_pull(skb, NSH_M_TYPE1_LEN);
+ __skb_pull(skb, ENCAP_ETH_LEN + NSH_M_TYPE1_LEN);
if(key->nsh.nsh_np == NSH_P_ETHERNET)
ret = key_extract(skb, key);
else
return -EINVAL;
- __skb_push(skb, NSH_M_TYPE1_LEN);
+ __skb_push(skb, ENCAP_ETH_LEN + NSH_M_TYPE1_LEN);
return ret;
} else {
- ovs_key_nsh_init(key, NSH_M_TYPE1_LEN);
+ ovs_key_nsh_init(key);
}
return 0;
@@ -760,7 +752,7 @@ static bool is_nsh_header(const void *tun_opts, __be16 tun_flags) {
if (tun_opts && (tun_flags & TUNNEL_VXLAN_OPT))
md = (struct vxlan_metadata *)tun_opts;
- if (md && (md->gpe & VXLAN_GPE_NP_MASK) == VXLAN_GPE_NP_NSH)
+ if (md && ((md->gpe & VXLAN_GPE_NP_MASK) == VXLAN_GPE_NP_NSH))
return true;
else
return false;
@@ -768,7 +760,7 @@ static bool is_nsh_header(const void *tun_opts, __be16 tun_flags) {
int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key)
{
- ovs_key_nsh_init(key, NSH_M_TYPE1_LEN);
+ ovs_key_nsh_init(key);
return key_extract(skb, key);
}
@@ -804,13 +796,13 @@ int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info,
key->recirc_id = 0;
/* Extract NSH and inner Ethernet if NSH header exists */
- if (tun_info && is_nsh_header(ip_tunnel_info_opts(tun_info), key->tun_key.tun_flags)) {
+ if (tun_info && is_nsh_header(TUN_METADATA_OPTS(key, key->tun_opts_len), key->tun_key.tun_flags)) {
int ret ;
ret = nsh_extract(skb, key);
if (key->nsh.nsh_mdtype)
return ret;
} else {
- ovs_key_nsh_init(key, NSH_M_TYPE1_LEN);
+ ovs_key_nsh_init(key);
}
return key_extract(skb, key);
}
@@ -833,7 +825,7 @@ int ovs_flow_key_extract_userspace(struct net *net, const struct nlattr *attr,
if (key->nsh.nsh_mdtype)
return ret;
} else {
- ovs_key_nsh_init(key, NSH_M_TYPE1_LEN);
+ ovs_key_nsh_init(key);
}
return key_extract(skb, key);
diff --git a/datapath/flow.h b/datapath/flow.h
index c8ccd5f..c00144a 100644
--- a/datapath/flow.h
+++ b/datapath/flow.h
@@ -63,21 +63,7 @@ struct sw_flow_key {
u32 skb_mark; /* SKB mark. */
u16 in_port; /* Input switch port (or DP_MAX_PORTS). */
} __packed phy; /* Safe when right after 'tun_key'. */
- struct {
- u32 nshc1; /* NSH context C1-C4 */
- u32 nshc2;
- u32 nshc3;
- u32 nshc4;
- u32 nsp; /* NSH path id */
- u8 nsi; /* NSH index */
- u8 nsh_mdtype; /* NSH metadata type */
- u8 nsh_np; /* NSH next protocol */
- }__packed nsh; /* network service header */
- struct {
- u8 encap_eth_src[ETH_ALEN]; /* ENCAP ethernet source address. */
- u8 encap_eth_dst[ETH_ALEN]; /* ENCAP ethernet destination address. */
- u16 encap_eth_type; /* ENCAP ethernet type. */
- } encap_eth;
+ struct ovs_key_nsh nsh; /* network service header */
u32 ovs_flow_hash; /* Datapath computed hash value. */
u32 recirc_id; /* Recirculation ID. */
struct {
diff --git a/datapath/flow_netlink.c b/datapath/flow_netlink.c
index ebfae37..3e26ac5 100644
--- a/datapath/flow_netlink.c
+++ b/datapath/flow_netlink.c
@@ -284,7 +284,7 @@ size_t ovs_key_attr_size(void)
/* Whenever adding new OVS_KEY_ FIELDS, we should consider
* updating this function.
*/
- BUILD_BUG_ON(OVS_KEY_ATTR_TUNNEL_INFO != 28);
+ BUILD_BUG_ON(OVS_KEY_ATTR_TUNNEL_INFO != 27);
return nla_total_size(4) /* OVS_KEY_ATTR_PRIORITY */
+ nla_total_size(0) /* OVS_KEY_ATTR_TUNNEL */
@@ -297,8 +297,7 @@ size_t ovs_key_attr_size(void)
+ nla_total_size(2) /* OVS_KEY_ATTR_CT_ZONE */
+ nla_total_size(4) /* OVS_KEY_ATTR_CT_MARK */
+ nla_total_size(16) /* OVS_KEY_ATTR_CT_LABELS */
- + nla_total_size(24) /* OVS_KEY_ATTR_NSH */
- + nla_total_size(14) /* OVS_KEY_ATTR_ENCAP_ETH */
+ + nla_total_size(40) /* OVS_KEY_ATTR_NSH */
+ nla_total_size(12) /* OVS_KEY_ATTR_ETHERNET */
+ nla_total_size(2) /* OVS_KEY_ATTR_ETHERTYPE */
+ nla_total_size(4) /* OVS_KEY_ATTR_VLAN */
@@ -337,7 +336,6 @@ static const struct ovs_len_tbl ovs_key_lens[OVS_KEY_ATTR_MAX + 1] = {
[OVS_KEY_ATTR_IN_PORT] = { .len = sizeof(u32) },
[OVS_KEY_ATTR_SKB_MARK] = { .len = sizeof(u32) },
[OVS_KEY_ATTR_NSH] = { .len = sizeof(struct ovs_key_nsh) },
- [OVS_KEY_ATTR_ENCAP_ETH] = { .len = sizeof(struct ovs_key_encap_eth) },
[OVS_KEY_ATTR_ETHERNET] = { .len = sizeof(struct ovs_key_ethernet) },
[OVS_KEY_ATTR_VLAN] = { .len = sizeof(__be16) },
[OVS_KEY_ATTR_ETHERTYPE] = { .len = sizeof(__be16) },
@@ -877,6 +875,12 @@ static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
const struct ovs_key_nsh *nsh_key;
nsh_key = nla_data(a[OVS_KEY_ATTR_NSH]);
+ SW_FLOW_KEY_MEMCPY(match, nsh.encap_eth_src,
+ nsh_key->encap_eth_src, ETH_ALEN, is_mask);
+ SW_FLOW_KEY_MEMCPY(match, nsh.encap_eth_dst,
+ nsh_key->encap_eth_dst, ETH_ALEN, is_mask);
+ SW_FLOW_KEY_PUT(match, nsh.encap_eth_type,
+ nsh_key->encap_eth_type, is_mask);
SW_FLOW_KEY_PUT(match, nsh.nshc1,
nsh_key->nshc1, is_mask);
SW_FLOW_KEY_PUT(match, nsh.nshc2,
@@ -896,19 +900,6 @@ static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
attrs &= ~(1ULL << OVS_KEY_ATTR_NSH);
}
- if (attrs & (1ULL << OVS_KEY_ATTR_ENCAP_ETH)) {
- const struct ovs_key_encap_eth *encap_eth_key;
-
- encap_eth_key = nla_data(a[OVS_KEY_ATTR_ENCAP_ETH]);
- SW_FLOW_KEY_MEMCPY(match, encap_eth.encap_eth_src,
- encap_eth_key->encap_eth_src, ETH_ALEN, is_mask);
- SW_FLOW_KEY_MEMCPY(match, encap_eth.encap_eth_dst,
- encap_eth_key->encap_eth_dst, ETH_ALEN, is_mask);
- SW_FLOW_KEY_PUT(match, encap_eth.encap_eth_type,
- encap_eth_key->encap_eth_type, is_mask);
- attrs &= ~(1ULL << OVS_KEY_ATTR_ENCAP_ETH);
- }
-
if (attrs & (1ULL << OVS_KEY_ATTR_ETHERNET)) {
const struct ovs_key_ethernet *eth_key;
@@ -1433,6 +1424,9 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
if (!nla)
goto nla_put_failure;
nsh_key = nla_data(nla);
+ memcpy(nsh_key->encap_eth_dst, output->nsh.encap_eth_dst, ETH_ALEN);
+ memcpy(nsh_key->encap_eth_src, output->nsh.encap_eth_src, ETH_ALEN);
+ nsh_key->encap_eth_type = output->nsh.encap_eth_type;
nsh_key->nsi = output->nsh.nsi;
nsh_key->nsp = output->nsh.nsp;
nsh_key->nsh_mdtype= output->nsh.nsh_mdtype;
@@ -1443,18 +1437,6 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
nsh_key->nshc4 = output->nsh.nshc4;
}
- if ((swkey->encap_eth.encap_eth_type || is_mask)) {
- struct ovs_key_encap_eth *encap_eth_key;
-
- nla = nla_reserve(skb, OVS_KEY_ATTR_ENCAP_ETH, sizeof(*encap_eth_key));
- if (!nla)
- goto nla_put_failure;
- encap_eth_key = nla_data(nla);
- memcpy(encap_eth_key->encap_eth_src, output->encap_eth.encap_eth_src, ETH_ALEN);
- memcpy(encap_eth_key->encap_eth_dst, output->encap_eth.encap_eth_dst, ETH_ALEN);
- encap_eth_key->encap_eth_type= output->encap_eth.encap_eth_type;
- }
-
if ((swkey->tun_key.u.ipv4.dst || is_mask)) {
const void *opts = NULL;
@@ -2253,8 +2235,6 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
[OVS_ACTION_ATTR_POP_VLAN] = 0,
[OVS_ACTION_ATTR_PUSH_NSH] = sizeof(struct ovs_action_push_nsh),
[OVS_ACTION_ATTR_POP_NSH] = 0,
- [OVS_ACTION_ATTR_PUSH_ETH] = sizeof(struct ovs_action_push_eth),
- [OVS_ACTION_ATTR_POP_ETH] = 0,
[OVS_ACTION_ATTR_SET] = (u32)-1,
[OVS_ACTION_ATTR_SET_MASKED] = (u32)-1,
[OVS_ACTION_ATTR_SAMPLE] = (u32)-1,
@@ -2301,8 +2281,6 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
case OVS_ACTION_ATTR_PUSH_NSH:
case OVS_ACTION_ATTR_POP_NSH:
- case OVS_ACTION_ATTR_PUSH_ETH:
- case OVS_ACTION_ATTR_POP_ETH:
break;
case OVS_ACTION_ATTR_POP_VLAN:
diff --git a/datapath/linux/compat/include/linux/openvswitch.h b/datapath/linux/compat/include/linux/openvswitch.h
index 187bb9b..bf1be4e 100644
--- a/datapath/linux/compat/include/linux/openvswitch.h
+++ b/datapath/linux/compat/include/linux/openvswitch.h
@@ -331,7 +331,6 @@ enum ovs_key_attr {
OVS_KEY_ATTR_IN_PORT, /* u32 OVS dp port number */
OVS_KEY_ATTR_NSH, /* struct ovs_key_nsh. Only support NSH MD
type 1 now */
- OVS_KEY_ATTR_ENCAP_ETH, /* struct ovs_key_encap_eth */
OVS_KEY_ATTR_ETHERNET, /* struct ovs_key_ethernet */
OVS_KEY_ATTR_VLAN, /* be16 VLAN TCI */
OVS_KEY_ATTR_ETHERTYPE, /* be16 Ethernet type */
@@ -406,6 +405,10 @@ enum ovs_frag_type {
#define OVS_FRAG_TYPE_MAX (__OVS_FRAG_TYPE_MAX - 1)
struct ovs_key_nsh {
+ __u8 encap_eth_dst[ETH_ALEN];
+ __u8 encap_eth_src[ETH_ALEN];
+ __u16 encap_eth_type;
+ __u16 pad1;
__u32 nshc1;
__u32 nshc2;
__u32 nshc3;
@@ -414,14 +417,8 @@ struct ovs_key_nsh {
__u8 nsi;
__u8 nsh_mdtype;
__u8 nsh_np;
- __u8 reserved;
-};
-
-struct ovs_key_encap_eth {
- __u8 encap_eth_src[ETH_ALEN];
- __u8 encap_eth_dst[ETH_ALEN];
- __u16 encap_eth_type;
-};
+ __u8 pad2;
+} __packed;
struct ovs_key_ethernet {
__u8 eth_src[ETH_ALEN];
@@ -652,6 +649,85 @@ struct ovs_action_push_vlan {
__be16 vlan_tci; /* 802.1Q TCI (VLAN ID and priority). */
};
+#ifndef __VXLAN_GPE_HEADER
+#define __VXLAN_GPE_HEADER 1
+
+/*
+ * VXLAN Generic Protocol Extension:
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |R|R|Ver|I|P|R|O|R|R|R|R|R|R|R|R|R|R|R|R|R|R|R|R| Next Proto |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | VXLAN Network Identifier (VNI) | Reserved |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * Ver = Version. Indicates VXLAN GPE protocol version. The initial
+ * version is 0. If a receiver does not support the version
+ * indicated it MUST drop the packet.
+ *
+ * I = Instance Bit. The I bit MUST be set to indicate a valid VNI.
+ *
+ * P = Next Protocol Bit. The P bit is set to indicate that the
+ * Next Protocol field is present.
+ *
+ * O = OAM Flag Bit. The O bit is set to indicate that the packet
+ * is an OAM packet.
+ *
+ * Next Protocol = This 8 bit field indicates the protocol header
+ * immediately following the VXLAN GPE header.
+ *
+ * [1] https://www.ietf.org/id/draft-ietf-nvo3-vxlan-gpe-01.txt
+ */
+
+struct vxlanhdr_gpe {
+#ifdef __LITTLE_ENDIAN_BITFIELD
+ uint8_t oam_flag:1;
+ uint8_t reserved_flags1:1;
+ uint8_t np_applied:1;
+ uint8_t instance_applied:1;
+ uint8_t gpe_version:2;
+ uint8_t reserved_flags2:2;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+ uint8_t reserved_flags2:2;
+ uint8_t gpe_version:2;
+ uint8_t instance_applied:1;
+ uint8_t np_applied:1;
+ uint8_t reserved_flags1:1;
+ uint8_t oam_flag:1;
+#else
+#error "Please fix <asm/byteorder.h>"
+#endif
+ uint8_t reserved_flags3;
+ uint8_t reserved_flags4;
+ uint8_t next_proto;
+ __be32 vx_vni;
+};
+
+/* VxLAN-GPE Header Next Protocol */
+#define VXLAN_GPE_NP_IPV4 0x01
+#define VXLAN_GPE_NP_IPV6 0x02
+#define VXLAN_GPE_NP_ETHERNET 0x03
+#define VXLAN_GPE_NP_NSH 0x04
+
+/* skb->mark mapping
+ *
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |R|R|Ver|I|P|R|O|R|R|R|R|R|R|R|R|R|R|R|R|R|R|R|R| Next Proto |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+#define VXLAN_GPE_OAM_FLAG (1UL << 24)
+#define VXLAN_GPE_NP_APPLIED (1UL << 26)
+#define VXLAN_GPE_INSTANCE_APPLIED (1UL << 27)
+#define VXLAN_GPE_VERSION ((1UL << 28) | (1UL << 29))
+
+#define VXLAN_GPE_NP_MASK (0xFF)
+#define VXLAN_GPE_USED_BITS (VXLAN_GPE_OAM_FLAG | VXLAN_GPE_NP_APPLIED \
+ | VXLAN_GPE_INSTANCE_APPLIED | VXLAN_GPE_VERSION | 0xFF)
+
+#define VXLAN_F_GPE 0x4000
+#define VXLAN_HF_GPE 0x04000000
+
+#endif /* __VXLAN_GPE_HEADER */
+
/*
* Network Service Header:
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -769,6 +845,7 @@ struct nsh_hdr {
#define ENCAP_ETH_LEN 14
+#define ETH_NSH_TYPE1_HEADER_SIZE (NSH_PUSH_TYPE1_HEADER_SIZE + ENCAP_ETH_LEN)
/**
* struct encap_eth - encap ethernet header for ethernet NSH
* @encap_eth_src: encap ethernet source address.
@@ -781,6 +858,11 @@ struct encap_eth_hdr {
__u16 encap_eth_type;
};
+struct eth_nsh_hdr {
+ struct encap_eth_hdr encap_eth_header;
+ struct nsh_hdr nsh_hdr __attribute__((packed));
+};
+
#define ENCAP_ETH_PUSH_HEADER_SIZE 14
/**
* struct ovs_action_push_nsh - %OVS_ACTION_ATTR_PUSH_NSH action argument.
@@ -791,15 +873,6 @@ struct ovs_action_push_nsh {
uint8_t header[NSH_PUSH_HEADER_SIZE];
};
-/**
- * struct ovs_action_push_nsh - %OVS_ACTION_ATTR_PUSH_NSH action argument.
- * @header
- */
-struct ovs_action_push_eth {
- uint16_t encap_eth_type;
- uint8_t header[ENCAP_ETH_PUSH_HEADER_SIZE];
-};
-
/* Data path hash algorithm for computing Datapath hash.
*
* The algorithm type only specifies the fields in a flow
@@ -839,6 +912,7 @@ struct ovs_action_push_tnl {
uint32_t out_port;
uint32_t header_len;
uint32_t tnl_type; /* For logging. */
+ uint32_t exts;
uint8_t header[TNL_PUSH_HEADER_SIZE];
};
#endif
@@ -965,8 +1039,6 @@ enum ovs_action_attr {
OVS_ACTION_ATTR_POP_VLAN, /* No argument. */
OVS_ACTION_ATTR_PUSH_NSH, /* struct ovs_action_push_nsh. */
OVS_ACTION_ATTR_POP_NSH, /* No argument. */
- OVS_ACTION_ATTR_PUSH_ETH, /* struct ovs_action_push_eth. */
- OVS_ACTION_ATTR_POP_ETH, /* No argument. */
OVS_ACTION_ATTR_SAMPLE, /* Nested OVS_SAMPLE_ATTR_*. */
OVS_ACTION_ATTR_RECIRC, /* u32 recirc_id. */
OVS_ACTION_ATTR_HASH, /* struct ovs_action_hash. */
diff --git a/datapath/linux/compat/include/net/vxlan.h b/datapath/linux/compat/include/net/vxlan.h
index 3aeac88..31f9e5e 100644
--- a/datapath/linux/compat/include/net/vxlan.h
+++ b/datapath/linux/compat/include/net/vxlan.h
@@ -84,6 +84,8 @@ struct vxlanhdr_gbp {
#define VXLAN_GBP_POLICY_APPLIED (BIT(3) << 16)
#define VXLAN_GBP_ID_MASK (0xFFFF)
+#ifndef __VXLAN_GPE_HEADER
+#define __VXLAN_GPE_HEADER 1
/*
* VXLAN Generic Protocol Extension:
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -156,6 +158,11 @@ struct vxlanhdr_gpe {
#define VXLAN_GPE_USED_BITS (VXLAN_GPE_OAM_FLAG | VXLAN_GPE_NP_APPLIED \
| VXLAN_GPE_INSTANCE_APPLIED | VXLAN_GPE_VERSION | 0xFF)
+#define VXLAN_HF_GPE BIT(26)
+#define VXLAN_F_GPE 0x4000
+
+#endif /* __VXLAN_GPE_HEADER */
+
/* VXLAN protocol header:
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |G|R|R|R|I|R|R|C| Reserved |
@@ -176,7 +183,6 @@ struct vxlanhdr {
#define VXLAN_HF_RCO BIT(21)
#define VXLAN_HF_VNI BIT(27)
#define VXLAN_HF_GBP BIT(31)
-#define VXLAN_HF_GPE BIT(26)
/* Remote checksum offload header option */
#define VXLAN_RCO_MASK 0x7f /* Last byte of vni field */
@@ -279,7 +285,6 @@ struct vxlan_dev {
#define VXLAN_F_GBP 0x800
#define VXLAN_F_REMCSUM_NOPARTIAL 0x1000
#define VXLAN_F_COLLECT_METADATA 0x2000
-#define VXLAN_F_GPE 0x4000
/* Flags that are used in the receive path. These flags must match in
* order for a socket to be shareable
diff --git a/datapath/linux/compat/vxlan.c b/datapath/linux/compat/vxlan.c
index 7ef051c..888d431 100644
--- a/datapath/linux/compat/vxlan.c
+++ b/datapath/linux/compat/vxlan.c
@@ -821,6 +821,7 @@ static void vxlan_rcv(struct vxlan_sock *vs, struct sk_buff *skb,
struct vxlan_dev *vxlan;
struct pcpu_sw_netstats *stats;
union vxlan_addr saddr;
+ struct eth_nsh_hdr *eth_nsh_header = NULL;
int err = 0;
/* For flow based devices, map all packets to VNI 0 */
@@ -888,6 +889,15 @@ static void vxlan_rcv(struct vxlan_sock *vs, struct sk_buff *skb,
stats->rx_packets++;
stats->rx_bytes += skb->len;
u64_stats_update_end(&stats->syncp);
+
+ /* Add a faked encap_eth_header for NSH */
+ if (md && ((md->gpe & VXLAN_GPE_NP_MASK) == VXLAN_GPE_NP_NSH)) {
+ skb_push(skb, ENCAP_ETH_LEN);
+ eth_nsh_header = (struct eth_nsh_hdr *)skb->data;
+ memmove(eth_nsh_header->encap_eth_header.encap_eth_dst, skb_mac_header(skb), ENCAP_ETH_LEN);
+ eth_nsh_header->encap_eth_header.encap_eth_type = htons(ETH_P_NSH);
+ }
+
netdev_port_receive(skb, skb_tunnel_info(skb));
return;
drop:
@@ -1178,6 +1188,11 @@ static int vxlan_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *sk
}
}
+ /* Skip encap_eth_header on sending Eth+NSH to vxlan-gpe port */
+ if (md && ((md->gpe & VXLAN_GPE_NP_MASK) == VXLAN_GPE_NP_NSH)) {
+ skb_pull(skb, ENCAP_ETH_LEN);
+ }
+
min_headroom = LL_RESERVED_SPACE(rt->dst.dev) + rt->dst.header_len
+ VXLAN_HLEN + sizeof(struct iphdr)
+ (skb_vlan_tag_present(skb) ? VLAN_HLEN : 0);
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 8e67bfd..d40cae4 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -467,7 +467,7 @@ static int get_port_by_name(struct dp_netdev *dp, const char *devname,
static void dp_netdev_free(struct dp_netdev *)
OVS_REQUIRES(dp_netdev_mutex);
static int do_add_port(struct dp_netdev *dp, const char *devname,
- const char *type, odp_port_t port_no)
+ const char *type, odp_port_t port_no, uint32_t exts)
OVS_REQUIRES(dp->port_mutex);
static void do_del_port(struct dp_netdev *dp, struct dp_netdev_port *)
OVS_REQUIRES(dp->port_mutex);
@@ -914,7 +914,7 @@ create_dp_netdev(const char *name, const struct dpif_class *class,
dp_netdev_set_nonpmd(dp);
ovs_mutex_lock(&dp->port_mutex);
- error = do_add_port(dp, name, "internal", ODPP_LOCAL);
+ error = do_add_port(dp, name, "internal", ODPP_LOCAL, 0);
ovs_mutex_unlock(&dp->port_mutex);
if (error) {
dp_netdev_free(dp);
@@ -1096,9 +1096,21 @@ hash_port_no(odp_port_t port_no)
return hash_int(odp_to_u32(port_no), 0);
}
+static void add_vxlan_gpe_exts(struct netdev *netdev, uint32_t exts)
+{
+ const char *type = netdev_get_type(netdev);
+ if (!strcmp(type, "vxlan")) {
+ struct netdev_tunnel_config *cfg;
+ cfg = netdev_get_tunnel_config(netdev);
+
+ if(exts & (1 << OVS_VXLAN_EXT_GPE))
+ cfg->exts |= (1 << OVS_VXLAN_EXT_GPE);
+ }
+}
+
static int
do_add_port(struct dp_netdev *dp, const char *devname, const char *type,
- odp_port_t port_no)
+ odp_port_t port_no, uint32_t exts)
OVS_REQUIRES(dp->port_mutex)
{
struct netdev_saved_flags *sf;
@@ -1145,7 +1157,8 @@ do_add_port(struct dp_netdev *dp, const char *devname, const char *type,
VLOG_ERR("%s, cannot set multiq", devname);
return errno;
}
- }
+ }
+ add_vxlan_gpe_exts(netdev, exts);
port = xzalloc(sizeof *port);
port->port_no = port_no;
port->netdev = netdev;
@@ -1211,7 +1224,12 @@ dpif_netdev_port_add(struct dpif *dpif, struct netdev *netdev,
}
if (!error) {
*port_nop = port_no;
- error = do_add_port(dp, dpif_port, netdev_get_type(netdev), port_no);
+ const struct netdev_tunnel_config *cfg;
+ uint32_t exts = 0;
+ cfg = netdev_get_tunnel_config(netdev);
+ if (cfg)
+ exts = cfg->exts;
+ error = do_add_port(dp, dpif_port, netdev_get_type(netdev), port_no, exts);
}
ovs_mutex_unlock(&dp->port_mutex);
@@ -3876,8 +3894,6 @@ dp_execute_cb(void *aux_, struct dp_packet **packets, int cnt,
case OVS_ACTION_ATTR_PUSH_NSH:
case OVS_ACTION_ATTR_POP_NSH:
- case OVS_ACTION_ATTR_PUSH_ETH:
- case OVS_ACTION_ATTR_POP_ETH:
case OVS_ACTION_ATTR_PUSH_VLAN:
case OVS_ACTION_ATTR_POP_VLAN:
case OVS_ACTION_ATTR_PUSH_MPLS:
diff --git a/lib/dpif.c b/lib/dpif.c
index b5265c4..481f0f9 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -1141,8 +1141,6 @@ dpif_execute_helper_cb(void *aux_, struct dp_packet **packets, int cnt,
case OVS_ACTION_ATTR_HASH:
case OVS_ACTION_ATTR_PUSH_NSH:
case OVS_ACTION_ATTR_POP_NSH:
- case OVS_ACTION_ATTR_PUSH_ETH:
- case OVS_ACTION_ATTR_POP_ETH:
case OVS_ACTION_ATTR_PUSH_VLAN:
case OVS_ACTION_ATTR_POP_VLAN:
case OVS_ACTION_ATTR_PUSH_MPLS:
diff --git a/lib/flow.c b/lib/flow.c
index fc8b98c..887b023 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -470,6 +470,25 @@ flow_extract(struct dp_packet *packet, struct flow *flow)
miniflow_expand(&m.mf, flow);
}
+/* parse Ethernet+NSH */
+static int parse_nsh(const void *data, struct ovs_key_nsh *nsh)
+{
+ memcpy(&nsh->encap_eth_dst, data, ENCAP_ETH_LEN);
+ const struct nsh_hdr *nsh_hdr = (const struct nsh_hdr *)((const char *)data + ENCAP_ETH_LEN);
+
+ nsh->nsh_mdtype = nsh_hdr->base.mdtype;
+ if (nsh->nsh_mdtype != NSH_M_TYPE1)
+ return -1;
+ nsh->nsh_np = nsh_hdr->base.proto;
+ nsh->nsi = nsh_hdr->base.svc_idx;
+ nsh->nsp = nsh_hdr->base.path_hdr << 8;
+ nsh->nshc1 = nsh_hdr->ctx.nshc1;
+ nsh->nshc2 = nsh_hdr->ctx.nshc2;
+ nsh->nshc3 = nsh_hdr->ctx.nshc3;
+ nsh->nshc4 = nsh_hdr->ctx.nshc4;
+ return 0;
+}
+
/* Caller is responsible for initializing 'dst' with enough storage for
* FLOW_U64S * 8 bytes. */
void
@@ -530,6 +549,32 @@ miniflow_extract(struct dp_packet *packet, struct miniflow *dst)
}
}
+ /* Extract Etherenet + NSH if the Ethernet type is 0x894F in packet */
+ if (OVS_UNLIKELY(size < sizeof(struct eth_header)))
+ goto out;
+ else {
+ const struct eth_header *eth = data;
+ if (eth->eth_type == htons(ETH_P_NSH)) {
+ /* extract Ethernet+nsh */
+ struct ovs_key_nsh nsh;
+ if (OVS_UNLIKELY(parse_nsh(data, &nsh)))
+ goto out;
+
+ /* Now only support NSH mdtype 1 */
+ if (nsh.nsh_mdtype == NSH_M_TYPE1){
+ /* Push all field related with Ethernet+nsh at once. */
+ miniflow_push_words(mf, encap_eth_dst, &nsh,
+ (sizeof (struct ovs_key_nsh)+sizeof(uint64_t) - 1) /
+ sizeof(uint64_t));
+ data = (const char *)data + NSH_M_TYPE1_LEN + ENCAP_ETH_LEN;
+ } else
+ goto out;
+
+ if(nsh.nsh_np != NSH_P_ETHERNET)
+ goto out;
+ }
+ }
+
/* Initialize packet's layer pointer and offsets. */
l2 = data;
dp_packet_reset_offsets(packet);
@@ -1291,6 +1336,9 @@ void flow_wildcards_init_for_packet(struct flow_wildcards *wc,
/* NSH fields wildcarded */
if (flow->nsh_mdtype) {
+ WC_MASK_FIELD(wc, encap_eth_src);
+ WC_MASK_FIELD(wc, encap_eth_dst);
+ WC_MASK_FIELD(wc, encap_eth_type);
WC_MASK_FIELD(wc, nshc1);
WC_MASK_FIELD(wc, nshc2);
WC_MASK_FIELD(wc, nshc3);
@@ -1301,13 +1349,6 @@ void flow_wildcards_init_for_packet(struct flow_wildcards *wc,
WC_MASK_FIELD(wc, nsi);
}
- /* ENCAP Eth wildcarded */
- if (flow->encap_eth_type) {
- WC_MASK_FIELD(wc, encap_eth_src);
- WC_MASK_FIELD(wc, encap_eth_dst);
- WC_MASK_FIELD(wc, encap_eth_type);
- }
-
/* metadata, regs, and conj_id wildcarded. */
WC_MASK_FIELD(wc, skb_priority);
@@ -1424,6 +1465,19 @@ flow_wc_map(const struct flow *flow, struct flowmap *map)
FLOWMAP_SET(map, ct_mark);
FLOWMAP_SET(map, ct_label);
+ /* NSH fields */
+ FLOWMAP_SET(map, encap_eth_src);
+ FLOWMAP_SET(map, encap_eth_dst);
+ FLOWMAP_SET(map, encap_eth_type);
+ FLOWMAP_SET(map, nshc1);
+ FLOWMAP_SET(map, nshc2);
+ FLOWMAP_SET(map, nshc3);
+ FLOWMAP_SET(map, nshc4);
+ FLOWMAP_SET(map, nsp);
+ FLOWMAP_SET(map, nsi);
+ FLOWMAP_SET(map, nsh_mdtype);
+ FLOWMAP_SET(map, nsh_np);
+
/* Ethertype-dependent fields. */
if (OVS_LIKELY(flow->dl_type == htons(ETH_TYPE_IP))) {
FLOWMAP_SET(map, nw_src);
@@ -2271,6 +2325,33 @@ flow_compose_l4(struct dp_packet *p, const struct flow *flow)
return l4_len;
}
+/* push ethernet+nsh header at the beginning of packets */
+static void
+flow_compose_nsh(struct dp_packet *p, const struct flow *flow)
+{
+ struct eth_nsh_hdr *eth_nsh_header;
+
+ /* Now only support mdtype1 */
+ if (flow->nsh_mdtype != NSH_M_TYPE1)
+ return;
+
+ eth_nsh_header = dp_packet_push_uninit(p, ETH_NSH_TYPE1_HEADER_SIZE);
+ eth_nsh_header->encap_eth_header.encap_eth_dst = flow->encap_eth_dst;
+ eth_nsh_header->encap_eth_header.encap_eth_src = flow->encap_eth_src;
+ eth_nsh_header->encap_eth_header.encap_eth_type = htons(ETH_P_NSH);
+
+ memset(ð_nsh_header->nsh_hdr, 0, sizeof (struct nsh_hdr));
+ eth_nsh_header->nsh_hdr.base.length = 6;
+ eth_nsh_header->nsh_hdr.base.proto = flow->nsh_np;
+ eth_nsh_header->nsh_hdr.base.mdtype = flow->nsh_mdtype;
+ eth_nsh_header->nsh_hdr.base.proto = flow->nsh_np;
+ eth_nsh_header->nsh_hdr.base.path_hdr = flow->nsp >> 8 | flow->nsi << 24;
+ eth_nsh_header->nsh_hdr.ctx.nshc1 = flow->nshc1;
+ eth_nsh_header->nsh_hdr.ctx.nshc2 = flow->nshc2;
+ eth_nsh_header->nsh_hdr.ctx.nshc3 = flow->nshc3;
+ eth_nsh_header->nsh_hdr.ctx.nshc4 = flow->nshc4;
+}
+
/* Puts into 'b' a packet that flow_extract() would parse as having the given
* 'flow'.
*
@@ -2371,6 +2452,10 @@ flow_compose(struct dp_packet *p, const struct flow *flow)
push_mpls(p, flow->dl_type, flow->mpls_lse[--n]);
}
}
+
+ if (flow->nsh_mdtype) {
+ flow_compose_nsh(p, flow);
+ }
}
/* Compressed flow. */
diff --git a/lib/flow.h b/lib/flow.h
index a8677b1..31a2a16 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -111,7 +111,11 @@ struct flow {
ofp_port_t actset_output; /* Output port in action set. */
uint8_t pad2[2]; /* Pad to 64 bits. */
- /* NSH (64-bit aligned) */
+ /* ETH + NSH (64-bit aligned) */
+ struct eth_addr encap_eth_dst; /* Encap ethernet destination address. */
+ struct eth_addr encap_eth_src; /* Encap ethernet source address. */
+ ovs_be16 encap_eth_type; /* Encap ethernet frame type. */
+ uint8_t pad3[2]; /* Pad to 64 bits. */
ovs_be32 nshc1;
ovs_be32 nshc2;
ovs_be32 nshc3;
@@ -120,13 +124,7 @@ struct flow {
uint8_t nsi;
uint8_t nsh_mdtype;
uint8_t nsh_np;
- uint8_t pad3;
-
- /* ENCAP_ETH (64-bit aligned) */
- struct eth_addr encap_eth_src; /* Encap ethernet source address. */
- struct eth_addr encap_eth_dst; /* Encap ethernet destination address. */
- ovs_be16 encap_eth_type; /* Encap ethernet frame type. */
- uint8_t pad4[2];
+ uint8_t pad4;
/* L2, Order the same as in the Ethernet header! (64-bit aligned) */
struct eth_addr dl_dst; /* Ethernet destination address. */
diff --git a/lib/match.c b/lib/match.c
index 3db2a2b..2b6648d 100644
--- a/lib/match.c
+++ b/lib/match.c
@@ -1002,12 +1002,12 @@ match_set_encap_eth_dst(struct match *match, const struct eth_addr encap_eth_dst
}
void
-match_set_encap_eth_type(struct match *match, uint16_t encap_eth_type)
+match_set_encap_eth_type(struct match *match, ovs_be16 encap_eth_type)
{
- match_set_encap_eth_type_masked(match, encap_eth_type, UINT16_MAX);
+ match->wc.masks.encap_eth_type = OVS_BE16_MAX;
+ match->flow.encap_eth_type = encap_eth_type;
}
-
/* Returns true if 'a' and 'b' wildcard the same fields and have the same
* values for fixed fields, otherwise false. */
bool
@@ -1338,12 +1338,11 @@ match_format(const struct match *match, struct ds *s, int priority)
wc->masks.nshc4);
}
- if (wc->masks.encap_eth_type) {
- ds_put_format(s, "encap_eth_type=%"PRIu16",", f->encap_eth_type);
- }
-
format_eth_masked(s, "encap_eth_src", f->encap_eth_src, wc->masks.encap_eth_src);
format_eth_masked(s, "encap_eth_dst", f->encap_eth_dst, wc->masks.encap_eth_dst);
+ if (wc->masks.encap_eth_type) {
+ ds_put_format(s, "encap_eth_type=0x%04"PRIx16",", ntohs(f->encap_eth_type));
+ }
if (wc->masks.dl_type) {
skip_type = true;
diff --git a/lib/match.h b/lib/match.h
index 529350e..bf27d38 100644
--- a/lib/match.h
+++ b/lib/match.h
@@ -187,7 +187,7 @@ void match_set_nshc3(struct match *, ovs_be32 nshc3);
void match_set_nshc4(struct match *, ovs_be32 nshc4);
void match_set_encap_eth_src(struct match *match, const struct eth_addr encap_eth_src);
void match_set_encap_eth_dst(struct match *match, const struct eth_addr encap_eth_dst);
-void match_set_encap_eth_type(struct match *match, uint16_t encap_eth_type);
+void match_set_encap_eth_type(struct match *match, ovs_be16 encap_eth_type);
bool match_equal(const struct match *, const struct match *);
uint32_t match_hash(const struct match *, uint32_t basis);