forked from openvswitch/ovs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta-flow.c
3663 lines (3163 loc) · 100 KB
/
meta-flow.c
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
/*
* Copyright (c) 2011-2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <config.h>
#include "openvswitch/meta-flow.h"
#include <errno.h>
#include <limits.h>
#include <netinet/icmp6.h>
#include <netinet/ip6.h>
#include "classifier.h"
#include "openvswitch/dynamic-string.h"
#include "nx-match.h"
#include "ovs-atomic.h"
#include "ovs-rcu.h"
#include "ovs-thread.h"
#include "packets.h"
#include "random.h"
#include "openvswitch/shash.h"
#include "socket-util.h"
#include "tun-metadata.h"
#include "unaligned.h"
#include "util.h"
#include "openvswitch/ofp-errors.h"
#include "openvswitch/ofp-match.h"
#include "openvswitch/ofp-port.h"
#include "openvswitch/vlog.h"
#include "vl-mff-map.h"
#include "openvswitch/nsh.h"
VLOG_DEFINE_THIS_MODULE(meta_flow);
#define FLOW_U32OFS(FIELD) \
offsetof(struct flow, FIELD) % 4 ? -1 : offsetof(struct flow, FIELD) / 4
#define MF_FIELD_SIZES(MEMBER) \
sizeof ((union mf_value *)0)->MEMBER, \
8 * sizeof ((union mf_value *)0)->MEMBER
extern const struct mf_field mf_fields[MFF_N_IDS]; /* Silence a warning. */
const struct mf_field mf_fields[MFF_N_IDS] = {
#include "meta-flow.inc"
};
/* Maps from an mf_field's 'name' or 'extra_name' to the mf_field. */
static struct shash mf_by_name;
/* Rate limit for parse errors. These always indicate a bug in an OpenFlow
* controller and so there's not much point in showing a lot of them. */
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
#define MF_VALUE_EXACT_8 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
#define MF_VALUE_EXACT_16 MF_VALUE_EXACT_8, MF_VALUE_EXACT_8
#define MF_VALUE_EXACT_32 MF_VALUE_EXACT_16, MF_VALUE_EXACT_16
#define MF_VALUE_EXACT_64 MF_VALUE_EXACT_32, MF_VALUE_EXACT_32
#define MF_VALUE_EXACT_128 MF_VALUE_EXACT_64, MF_VALUE_EXACT_64
#define MF_VALUE_EXACT_INITIALIZER { .tun_metadata = { MF_VALUE_EXACT_128 } }
const union mf_value exact_match_mask = MF_VALUE_EXACT_INITIALIZER;
static void nxm_init(void);
/* Returns the field with the given 'name', or a null pointer if no field has
* that name. */
const struct mf_field *
mf_from_name(const char *name)
{
nxm_init();
return shash_find_data(&mf_by_name, name);
}
/* Returns the field with the given 'name' (which is 'len' bytes long), or a
* null pointer if no field has that name. */
const struct mf_field *
mf_from_name_len(const char *name, size_t len)
{
nxm_init();
struct shash_node *node = shash_find_len(&mf_by_name, name, len);
return node ? node->data : NULL;
}
static void
nxm_do_init(void)
{
int i;
shash_init(&mf_by_name);
for (i = 0; i < MFF_N_IDS; i++) {
const struct mf_field *mf = &mf_fields[i];
ovs_assert(mf->id == i); /* Fields must be in the enum order. */
shash_add_once(&mf_by_name, mf->name, mf);
if (mf->extra_name) {
shash_add_once(&mf_by_name, mf->extra_name, mf);
}
}
}
static void
nxm_init(void)
{
static pthread_once_t once = PTHREAD_ONCE_INIT;
pthread_once(&once, nxm_do_init);
}
/* Consider the two value/mask pairs 'a_value/a_mask' and 'b_value/b_mask' as
* restrictions on a field's value. Then, this function initializes
* 'dst_value/dst_mask' such that it combines the restrictions of both pairs.
* This is not always possible, i.e. if one pair insists on a value of 0 in
* some bit and the other pair insists on a value of 1 in that bit. This
* function returns false in a case where the combined restriction is
* impossible (in which case 'dst_value/dst_mask' is not fully initialized),
* true otherwise.
*
* (As usually true for value/mask pairs in OVS, any 1-bit in a value must have
* a corresponding 1-bit in its mask.) */
bool
mf_subvalue_intersect(const union mf_subvalue *a_value,
const union mf_subvalue *a_mask,
const union mf_subvalue *b_value,
const union mf_subvalue *b_mask,
union mf_subvalue *dst_value,
union mf_subvalue *dst_mask)
{
for (int i = 0; i < ARRAY_SIZE(a_value->be64); i++) {
ovs_be64 av = a_value->be64[i];
ovs_be64 am = a_mask->be64[i];
ovs_be64 bv = b_value->be64[i];
ovs_be64 bm = b_mask->be64[i];
ovs_be64 *dv = &dst_value->be64[i];
ovs_be64 *dm = &dst_mask->be64[i];
if ((av ^ bv) & (am & bm)) {
return false;
}
*dv = av | bv;
*dm = am | bm;
}
return true;
}
/* Returns the "number of bits" in 'v', e.g. 1 if only the lowest-order bit is
* set, 2 if the second-lowest-order bit is set, and so on. */
int
mf_subvalue_width(const union mf_subvalue *v)
{
return 1 + bitwise_rscan(v, sizeof *v, true, sizeof *v * 8 - 1, -1);
}
/* For positive 'n', shifts the bits in 'value' 'n' bits to the left, and for
* negative 'n', shifts the bits '-n' bits to the right. */
void
mf_subvalue_shift(union mf_subvalue *value, int n)
{
if (n) {
union mf_subvalue tmp;
memset(&tmp, 0, sizeof tmp);
if (n > 0 && n < 8 * sizeof tmp) {
bitwise_copy(value, sizeof *value, 0,
&tmp, sizeof tmp, n,
8 * sizeof tmp - n);
} else if (n < 0 && n > -8 * sizeof tmp) {
bitwise_copy(value, sizeof *value, -n,
&tmp, sizeof tmp, 0,
8 * sizeof tmp + n);
}
*value = tmp;
}
}
/* Appends a formatted representation of 'sv' to 's'. */
void
mf_subvalue_format(const union mf_subvalue *sv, struct ds *s)
{
ds_put_hex(s, sv, sizeof *sv);
}
/* Returns true if 'wc' wildcards all the bits in field 'mf', false if 'wc'
* specifies at least one bit in the field.
*
* The caller is responsible for ensuring that 'wc' corresponds to a flow that
* meets 'mf''s prerequisites. */
bool
mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc)
{
switch (mf->id) {
case MFF_DP_HASH:
return !wc->masks.dp_hash;
case MFF_RECIRC_ID:
return !wc->masks.recirc_id;
case MFF_PACKET_TYPE:
return !wc->masks.packet_type;
case MFF_CONJ_ID:
return !wc->masks.conj_id;
case MFF_TUN_SRC:
return !wc->masks.tunnel.ip_src;
case MFF_TUN_DST:
return !wc->masks.tunnel.ip_dst;
case MFF_TUN_IPV6_SRC:
return ipv6_mask_is_any(&wc->masks.tunnel.ipv6_src);
case MFF_TUN_IPV6_DST:
return ipv6_mask_is_any(&wc->masks.tunnel.ipv6_dst);
case MFF_TUN_ID:
return !wc->masks.tunnel.tun_id;
case MFF_TUN_TOS:
return !wc->masks.tunnel.ip_tos;
case MFF_TUN_TTL:
return !wc->masks.tunnel.ip_ttl;
case MFF_TUN_FLAGS:
return !(wc->masks.tunnel.flags & FLOW_TNL_PUB_F_MASK);
case MFF_TUN_GBP_ID:
return !wc->masks.tunnel.gbp_id;
case MFF_TUN_GBP_FLAGS:
return !wc->masks.tunnel.gbp_flags;
case MFF_TUN_ERSPAN_VER:
return !wc->masks.tunnel.erspan_ver;
case MFF_TUN_ERSPAN_IDX:
return !wc->masks.tunnel.erspan_idx;
case MFF_TUN_ERSPAN_DIR:
return !wc->masks.tunnel.erspan_dir;
case MFF_TUN_ERSPAN_HWID:
return !wc->masks.tunnel.erspan_hwid;
CASE_MFF_TUN_METADATA:
return !ULLONG_GET(wc->masks.tunnel.metadata.present.map,
mf->id - MFF_TUN_METADATA0);
case MFF_METADATA:
return !wc->masks.metadata;
case MFF_IN_PORT:
case MFF_IN_PORT_OXM:
return !wc->masks.in_port.ofp_port;
case MFF_SKB_PRIORITY:
return !wc->masks.skb_priority;
case MFF_PKT_MARK:
return !wc->masks.pkt_mark;
case MFF_CT_STATE:
return !wc->masks.ct_state;
case MFF_CT_ZONE:
return !wc->masks.ct_zone;
case MFF_CT_MARK:
return !wc->masks.ct_mark;
case MFF_CT_LABEL:
return ovs_u128_is_zero(wc->masks.ct_label);
case MFF_CT_NW_PROTO:
return !wc->masks.ct_nw_proto;
case MFF_CT_NW_SRC:
return !wc->masks.ct_nw_src;
case MFF_CT_NW_DST:
return !wc->masks.ct_nw_dst;
case MFF_CT_TP_SRC:
return !wc->masks.ct_tp_src;
case MFF_CT_TP_DST:
return !wc->masks.ct_tp_dst;
case MFF_CT_IPV6_SRC:
return ipv6_mask_is_any(&wc->masks.ct_ipv6_src);
case MFF_CT_IPV6_DST:
return ipv6_mask_is_any(&wc->masks.ct_ipv6_dst);
CASE_MFF_REGS:
return !wc->masks.regs[mf->id - MFF_REG0];
CASE_MFF_XREGS:
return !flow_get_xreg(&wc->masks, mf->id - MFF_XREG0);
CASE_MFF_XXREGS: {
ovs_u128 value = flow_get_xxreg(&wc->masks, mf->id - MFF_XXREG0);
return ovs_u128_is_zero(value);
}
case MFF_ACTSET_OUTPUT:
return !wc->masks.actset_output;
case MFF_ETH_SRC:
return eth_addr_is_zero(wc->masks.dl_src);
case MFF_ETH_DST:
return eth_addr_is_zero(wc->masks.dl_dst);
case MFF_ETH_TYPE:
return !wc->masks.dl_type;
case MFF_ARP_SHA:
case MFF_ND_SLL:
return eth_addr_is_zero(wc->masks.arp_sha);
case MFF_ARP_THA:
case MFF_ND_TLL:
return eth_addr_is_zero(wc->masks.arp_tha);
case MFF_VLAN_TCI:
return !wc->masks.vlans[0].tci;
case MFF_DL_VLAN:
return !(wc->masks.vlans[0].tci & htons(VLAN_VID_MASK));
case MFF_VLAN_VID:
return !(wc->masks.vlans[0].tci & htons(VLAN_VID_MASK | VLAN_CFI));
case MFF_DL_VLAN_PCP:
case MFF_VLAN_PCP:
return !(wc->masks.vlans[0].tci & htons(VLAN_PCP_MASK));
case MFF_MPLS_LABEL:
return !(wc->masks.mpls_lse[0] & htonl(MPLS_LABEL_MASK));
case MFF_MPLS_TC:
return !(wc->masks.mpls_lse[0] & htonl(MPLS_TC_MASK));
case MFF_MPLS_BOS:
return !(wc->masks.mpls_lse[0] & htonl(MPLS_BOS_MASK));
case MFF_MPLS_TTL:
return !(wc->masks.mpls_lse[0] & htonl(MPLS_TTL_MASK));
case MFF_IPV4_SRC:
return !wc->masks.nw_src;
case MFF_IPV4_DST:
return !wc->masks.nw_dst;
case MFF_IPV6_SRC:
return ipv6_mask_is_any(&wc->masks.ipv6_src);
case MFF_IPV6_DST:
return ipv6_mask_is_any(&wc->masks.ipv6_dst);
case MFF_IPV6_LABEL:
return !wc->masks.ipv6_label;
case MFF_IP_PROTO:
return !wc->masks.nw_proto;
case MFF_IP_DSCP:
case MFF_IP_DSCP_SHIFTED:
return !(wc->masks.nw_tos & IP_DSCP_MASK);
case MFF_IP_ECN:
return !(wc->masks.nw_tos & IP_ECN_MASK);
case MFF_IP_TTL:
return !wc->masks.nw_ttl;
case MFF_ND_TARGET:
return ipv6_mask_is_any(&wc->masks.nd_target);
case MFF_ND_RESERVED:
return !wc->masks.igmp_group_ip4;
case MFF_ND_OPTIONS_TYPE:
return !wc->masks.tcp_flags;
case MFF_IP_FRAG:
return !(wc->masks.nw_frag & FLOW_NW_FRAG_MASK);
case MFF_ARP_OP:
return !wc->masks.nw_proto;
case MFF_ARP_SPA:
return !wc->masks.nw_src;
case MFF_ARP_TPA:
return !wc->masks.nw_dst;
case MFF_TCP_SRC:
case MFF_UDP_SRC:
case MFF_SCTP_SRC:
case MFF_ICMPV4_TYPE:
case MFF_ICMPV6_TYPE:
return !wc->masks.tp_src;
case MFF_TCP_DST:
case MFF_UDP_DST:
case MFF_SCTP_DST:
case MFF_ICMPV4_CODE:
case MFF_ICMPV6_CODE:
return !wc->masks.tp_dst;
case MFF_TCP_FLAGS:
return !wc->masks.tcp_flags;
case MFF_NSH_FLAGS:
return !wc->masks.nsh.flags;
case MFF_NSH_TTL:
return !wc->masks.nsh.ttl;
case MFF_NSH_MDTYPE:
return !wc->masks.nsh.mdtype;
case MFF_NSH_NP:
return !wc->masks.nsh.np;
case MFF_NSH_SPI:
return !(wc->masks.nsh.path_hdr & htonl(NSH_SPI_MASK));
case MFF_NSH_SI:
return !(wc->masks.nsh.path_hdr & htonl(NSH_SI_MASK));
case MFF_NSH_C1:
case MFF_NSH_C2:
case MFF_NSH_C3:
case MFF_NSH_C4:
return !wc->masks.nsh.context[mf->id - MFF_NSH_C1];
case MFF_TUN_GTPU_FLAGS:
return !wc->masks.tunnel.gtpu_flags;
case MFF_TUN_GTPU_MSGTYPE:
return !wc->masks.tunnel.gtpu_msgtype;
case MFF_N_IDS:
default:
OVS_NOT_REACHED();
}
}
/* Initializes 'mask' with the wildcard bit pattern for field 'mf' within 'wc'.
* Each bit in 'mask' will be set to 1 if the bit is significant for matching
* purposes, or to 0 if it is wildcarded.
*
* The caller is responsible for ensuring that 'wc' corresponds to a flow that
* meets 'mf''s prerequisites. */
void
mf_get_mask(const struct mf_field *mf, const struct flow_wildcards *wc,
union mf_value *mask)
{
mf_get_value(mf, &wc->masks, mask);
}
/* Tests whether 'mask' is a valid wildcard bit pattern for 'mf'. Returns true
* if the mask is valid, false otherwise. */
bool
mf_is_mask_valid(const struct mf_field *mf, const union mf_value *mask)
{
switch (mf->maskable) {
case MFM_NONE:
return (is_all_zeros(mask, mf->n_bytes) ||
is_all_ones(mask, mf->n_bytes));
case MFM_FULLY:
return true;
}
OVS_NOT_REACHED();
}
/* Returns true if 'flow' meets the prerequisites for 'mf', false otherwise.
* If a non-NULL 'mask' is passed, zero-valued matches can also be verified.
* Sets inspected bits in 'wc', if non-NULL. */
static bool
mf_are_prereqs_ok__(const struct mf_field *mf, const struct flow *flow,
const struct flow_wildcards *mask,
struct flow_wildcards *wc)
{
ovs_be16 dl_type = get_dl_type(flow);
switch (mf->prereqs) {
case MFP_NONE:
return true;
case MFP_ETHERNET:
return is_ethernet(flow, wc);
case MFP_ARP:
return (dl_type == htons(ETH_TYPE_ARP) ||
dl_type == htons(ETH_TYPE_RARP));
case MFP_IPV4:
return dl_type == htons(ETH_TYPE_IP);
case MFP_IPV6:
return dl_type == htons(ETH_TYPE_IPV6);
case MFP_VLAN_VID:
return is_vlan(flow, wc);
case MFP_MPLS:
return eth_type_mpls(dl_type);
case MFP_IP_ANY:
return is_ip_any(flow);
case MFP_NSH:
return dl_type == htons(ETH_TYPE_NSH);
case MFP_CT_VALID:
return is_ct_valid(flow, mask, wc);
case MFP_TCP:
/* Matching !FRAG_LATER is not enforced (mask is not checked). */
return is_tcp(flow, wc) && !(flow->nw_frag & FLOW_NW_FRAG_LATER);
case MFP_UDP:
return is_udp(flow, wc) && !(flow->nw_frag & FLOW_NW_FRAG_LATER);
case MFP_SCTP:
return is_sctp(flow, wc) && !(flow->nw_frag & FLOW_NW_FRAG_LATER);
case MFP_ICMPV4:
return is_icmpv4(flow, wc);
case MFP_ICMPV6:
return is_icmpv6(flow, wc);
case MFP_ND:
return is_nd(flow, wc);
case MFP_ND_SOLICIT:
return is_nd(flow, wc) && flow->tp_src == htons(ND_NEIGHBOR_SOLICIT);
case MFP_ND_ADVERT:
return is_nd(flow, wc) && flow->tp_src == htons(ND_NEIGHBOR_ADVERT);
}
OVS_NOT_REACHED();
}
/* Returns true if 'flow' meets the prerequisites for 'mf', false otherwise.
* Sets inspected bits in 'wc', if non-NULL. */
bool
mf_are_prereqs_ok(const struct mf_field *mf, const struct flow *flow,
struct flow_wildcards *wc)
{
return mf_are_prereqs_ok__(mf, flow, NULL, wc);
}
/* Returns true if 'match' meets the prerequisites for 'mf', false otherwise.
*/
bool
mf_are_match_prereqs_ok(const struct mf_field *mf, const struct match *match)
{
return mf_are_prereqs_ok__(mf, &match->flow, &match->wc, NULL);
}
/* Returns true if 'value' may be a valid value *as part of a masked match*,
* false otherwise.
*
* A value is not rejected just because it is not valid for the field in
* question, but only if it doesn't make sense to test the bits in question at
* all. For example, the MFF_VLAN_TCI field will never have a nonzero value
* without the VLAN_CFI bit being set, but we can't reject those values because
* it is still legitimate to test just for those bits (see the documentation
* for NXM_OF_VLAN_TCI in meta-flow.h). On the other hand, there is never a
* reason to set the low bit of MFF_IP_DSCP to 1, so we reject that. */
bool
mf_is_value_valid(const struct mf_field *mf, const union mf_value *value)
{
switch (mf->id) {
case MFF_DP_HASH:
case MFF_RECIRC_ID:
case MFF_PACKET_TYPE:
case MFF_CONJ_ID:
case MFF_TUN_ID:
case MFF_TUN_SRC:
case MFF_TUN_DST:
case MFF_TUN_IPV6_SRC:
case MFF_TUN_IPV6_DST:
case MFF_TUN_TOS:
case MFF_TUN_TTL:
case MFF_TUN_GBP_ID:
case MFF_TUN_GBP_FLAGS:
case MFF_TUN_ERSPAN_IDX:
case MFF_TUN_ERSPAN_VER:
case MFF_TUN_ERSPAN_DIR:
case MFF_TUN_ERSPAN_HWID:
case MFF_TUN_GTPU_FLAGS:
case MFF_TUN_GTPU_MSGTYPE:
CASE_MFF_TUN_METADATA:
case MFF_METADATA:
case MFF_IN_PORT:
case MFF_SKB_PRIORITY:
case MFF_PKT_MARK:
case MFF_CT_ZONE:
case MFF_CT_MARK:
case MFF_CT_LABEL:
case MFF_CT_NW_PROTO:
case MFF_CT_NW_SRC:
case MFF_CT_NW_DST:
case MFF_CT_IPV6_SRC:
case MFF_CT_IPV6_DST:
case MFF_CT_TP_SRC:
case MFF_CT_TP_DST:
CASE_MFF_REGS:
CASE_MFF_XREGS:
CASE_MFF_XXREGS:
case MFF_ETH_SRC:
case MFF_ETH_DST:
case MFF_ETH_TYPE:
case MFF_VLAN_TCI:
case MFF_MPLS_TTL:
case MFF_IPV4_SRC:
case MFF_IPV4_DST:
case MFF_IPV6_SRC:
case MFF_IPV6_DST:
case MFF_IP_PROTO:
case MFF_IP_TTL:
case MFF_ARP_SPA:
case MFF_ARP_TPA:
case MFF_ARP_SHA:
case MFF_ARP_THA:
case MFF_TCP_SRC:
case MFF_TCP_DST:
case MFF_UDP_SRC:
case MFF_UDP_DST:
case MFF_SCTP_SRC:
case MFF_SCTP_DST:
case MFF_ICMPV4_TYPE:
case MFF_ICMPV4_CODE:
case MFF_ICMPV6_TYPE:
case MFF_ICMPV6_CODE:
case MFF_ND_TARGET:
case MFF_ND_SLL:
case MFF_ND_TLL:
case MFF_ND_RESERVED:
case MFF_ND_OPTIONS_TYPE:
return true;
case MFF_IN_PORT_OXM:
case MFF_ACTSET_OUTPUT: {
ofp_port_t port;
return !ofputil_port_from_ofp11(value->be32, &port);
}
case MFF_IP_DSCP:
return !(value->u8 & ~IP_DSCP_MASK);
case MFF_IP_DSCP_SHIFTED:
return !(value->u8 & (~IP_DSCP_MASK >> 2));
case MFF_IP_ECN:
return !(value->u8 & ~IP_ECN_MASK);
case MFF_IP_FRAG:
return !(value->u8 & ~FLOW_NW_FRAG_MASK);
case MFF_TCP_FLAGS:
return !(value->be16 & ~htons(0x0fff));
case MFF_ARP_OP:
return !(value->be16 & htons(0xff00));
case MFF_DL_VLAN:
return !(value->be16 & htons(VLAN_CFI | VLAN_PCP_MASK));
case MFF_VLAN_VID:
return !(value->be16 & htons(VLAN_PCP_MASK));
case MFF_DL_VLAN_PCP:
case MFF_VLAN_PCP:
return !(value->u8 & ~(VLAN_PCP_MASK >> VLAN_PCP_SHIFT));
case MFF_IPV6_LABEL:
return !(value->be32 & ~htonl(IPV6_LABEL_MASK));
case MFF_MPLS_LABEL:
return !(value->be32 & ~htonl(MPLS_LABEL_MASK >> MPLS_LABEL_SHIFT));
case MFF_MPLS_TC:
return !(value->u8 & ~(MPLS_TC_MASK >> MPLS_TC_SHIFT));
case MFF_MPLS_BOS:
return !(value->u8 & ~(MPLS_BOS_MASK >> MPLS_BOS_SHIFT));
case MFF_TUN_FLAGS:
return !(value->be16 & ~htons(FLOW_TNL_PUB_F_MASK));
case MFF_CT_STATE:
return !(value->be32 & ~htonl(CS_SUPPORTED_MASK));
case MFF_NSH_FLAGS:
return true;
case MFF_NSH_TTL:
return (value->u8 <= 63);
case MFF_NSH_MDTYPE:
return (value->u8 == 1 || value->u8 == 2);
case MFF_NSH_NP:
return true;
case MFF_NSH_SPI:
return !(value->be32 & htonl(0xFF000000));
case MFF_NSH_SI:
case MFF_NSH_C1:
case MFF_NSH_C2:
case MFF_NSH_C3:
case MFF_NSH_C4:
return true;
case MFF_N_IDS:
default:
OVS_NOT_REACHED();
}
}
/* Copies the value of field 'mf' from 'flow' into 'value'. The caller is
* responsible for ensuring that 'flow' meets 'mf''s prerequisites. */
void
mf_get_value(const struct mf_field *mf, const struct flow *flow,
union mf_value *value)
{
switch (mf->id) {
case MFF_DP_HASH:
value->be32 = htonl(flow->dp_hash);
break;
case MFF_RECIRC_ID:
value->be32 = htonl(flow->recirc_id);
break;
case MFF_PACKET_TYPE:
value->be32 = flow->packet_type;
break;
case MFF_CONJ_ID:
value->be32 = htonl(flow->conj_id);
break;
case MFF_TUN_ID:
value->be64 = flow->tunnel.tun_id;
break;
case MFF_TUN_SRC:
value->be32 = flow->tunnel.ip_src;
break;
case MFF_TUN_DST:
value->be32 = flow->tunnel.ip_dst;
break;
case MFF_TUN_IPV6_SRC:
value->ipv6 = flow->tunnel.ipv6_src;
break;
case MFF_TUN_IPV6_DST:
value->ipv6 = flow->tunnel.ipv6_dst;
break;
case MFF_TUN_FLAGS:
value->be16 = htons(flow->tunnel.flags & FLOW_TNL_PUB_F_MASK);
break;
case MFF_TUN_GBP_ID:
value->be16 = flow->tunnel.gbp_id;
break;
case MFF_TUN_GBP_FLAGS:
value->u8 = flow->tunnel.gbp_flags;
break;
case MFF_TUN_TTL:
value->u8 = flow->tunnel.ip_ttl;
break;
case MFF_TUN_TOS:
value->u8 = flow->tunnel.ip_tos;
break;
case MFF_TUN_ERSPAN_VER:
value->u8 = flow->tunnel.erspan_ver;
break;
case MFF_TUN_ERSPAN_IDX:
value->be32 = htonl(flow->tunnel.erspan_idx);
break;
case MFF_TUN_ERSPAN_DIR:
value->u8 = flow->tunnel.erspan_dir;
break;
case MFF_TUN_ERSPAN_HWID:
value->u8 = flow->tunnel.erspan_hwid;
break;
case MFF_TUN_GTPU_FLAGS:
value->u8 = flow->tunnel.gtpu_flags;
break;
case MFF_TUN_GTPU_MSGTYPE:
value->u8 = flow->tunnel.gtpu_msgtype;
break;
CASE_MFF_TUN_METADATA:
tun_metadata_read(&flow->tunnel, mf, value);
break;
case MFF_METADATA:
value->be64 = flow->metadata;
break;
case MFF_IN_PORT:
value->be16 = htons(ofp_to_u16(flow->in_port.ofp_port));
break;
case MFF_IN_PORT_OXM:
value->be32 = ofputil_port_to_ofp11(flow->in_port.ofp_port);
break;
case MFF_ACTSET_OUTPUT:
value->be32 = ofputil_port_to_ofp11(flow->actset_output);
break;
case MFF_SKB_PRIORITY:
value->be32 = htonl(flow->skb_priority);
break;
case MFF_PKT_MARK:
value->be32 = htonl(flow->pkt_mark);
break;
case MFF_CT_STATE:
value->be32 = htonl(flow->ct_state);
break;
case MFF_CT_ZONE:
value->be16 = htons(flow->ct_zone);
break;
case MFF_CT_MARK:
value->be32 = htonl(flow->ct_mark);
break;
case MFF_CT_LABEL:
value->be128 = hton128(flow->ct_label);
break;
case MFF_CT_NW_PROTO:
value->u8 = flow->ct_nw_proto;
break;
case MFF_CT_NW_SRC:
value->be32 = flow->ct_nw_src;
break;
case MFF_CT_NW_DST:
value->be32 = flow->ct_nw_dst;
break;
case MFF_CT_IPV6_SRC:
value->ipv6 = flow->ct_ipv6_src;
break;
case MFF_CT_IPV6_DST:
value->ipv6 = flow->ct_ipv6_dst;
break;
case MFF_CT_TP_SRC:
value->be16 = flow->ct_tp_src;
break;
case MFF_CT_TP_DST:
value->be16 = flow->ct_tp_dst;
break;
CASE_MFF_REGS:
value->be32 = htonl(flow->regs[mf->id - MFF_REG0]);
break;
CASE_MFF_XREGS:
value->be64 = htonll(flow_get_xreg(flow, mf->id - MFF_XREG0));
break;
CASE_MFF_XXREGS:
value->be128 = hton128(flow_get_xxreg(flow, mf->id - MFF_XXREG0));
break;
case MFF_ETH_SRC:
value->mac = flow->dl_src;
break;
case MFF_ETH_DST:
value->mac = flow->dl_dst;
break;
case MFF_ETH_TYPE:
value->be16 = flow->dl_type;
break;
case MFF_VLAN_TCI:
value->be16 = flow->vlans[0].tci;
break;
case MFF_DL_VLAN:
value->be16 = flow->vlans[0].tci & htons(VLAN_VID_MASK);
break;
case MFF_VLAN_VID:
value->be16 = flow->vlans[0].tci & htons(VLAN_VID_MASK | VLAN_CFI);
break;
case MFF_DL_VLAN_PCP:
case MFF_VLAN_PCP:
value->u8 = vlan_tci_to_pcp(flow->vlans[0].tci);
break;
case MFF_MPLS_LABEL:
value->be32 = htonl(mpls_lse_to_label(flow->mpls_lse[0]));
break;
case MFF_MPLS_TC:
value->u8 = mpls_lse_to_tc(flow->mpls_lse[0]);
break;
case MFF_MPLS_BOS:
value->u8 = mpls_lse_to_bos(flow->mpls_lse[0]);
break;
case MFF_MPLS_TTL:
value->u8 = mpls_lse_to_ttl(flow->mpls_lse[0]);
break;
case MFF_IPV4_SRC:
value->be32 = flow->nw_src;
break;
case MFF_IPV4_DST:
value->be32 = flow->nw_dst;
break;
case MFF_IPV6_SRC:
value->ipv6 = flow->ipv6_src;
break;
case MFF_IPV6_DST:
value->ipv6 = flow->ipv6_dst;
break;
case MFF_IPV6_LABEL:
value->be32 = flow->ipv6_label;
break;
case MFF_IP_PROTO:
value->u8 = flow->nw_proto;
break;
case MFF_IP_DSCP:
value->u8 = flow->nw_tos & IP_DSCP_MASK;
break;
case MFF_IP_DSCP_SHIFTED:
value->u8 = flow->nw_tos >> 2;
break;
case MFF_IP_ECN:
value->u8 = flow->nw_tos & IP_ECN_MASK;
break;
case MFF_IP_TTL:
value->u8 = flow->nw_ttl;
break;
case MFF_IP_FRAG:
value->u8 = flow->nw_frag;
break;
case MFF_ARP_OP:
value->be16 = htons(flow->nw_proto);
break;
case MFF_ARP_SPA:
value->be32 = flow->nw_src;
break;
case MFF_ARP_TPA:
value->be32 = flow->nw_dst;
break;
case MFF_ARP_SHA:
case MFF_ND_SLL:
value->mac = flow->arp_sha;
break;
case MFF_ARP_THA:
case MFF_ND_TLL:
value->mac = flow->arp_tha;
break;
case MFF_TCP_SRC:
case MFF_UDP_SRC:
case MFF_SCTP_SRC:
value->be16 = flow->tp_src;
break;
case MFF_TCP_DST:
case MFF_UDP_DST:
case MFF_SCTP_DST:
value->be16 = flow->tp_dst;
break;
case MFF_TCP_FLAGS:
case MFF_ND_OPTIONS_TYPE:
value->be16 = flow->tcp_flags;
break;
case MFF_ND_RESERVED:
value->be32 = flow->igmp_group_ip4;
break;
case MFF_ICMPV4_TYPE:
case MFF_ICMPV6_TYPE:
value->u8 = ntohs(flow->tp_src);
break;
case MFF_ICMPV4_CODE:
case MFF_ICMPV6_CODE:
value->u8 = ntohs(flow->tp_dst);
break;
case MFF_ND_TARGET:
value->ipv6 = flow->nd_target;
break;
case MFF_NSH_FLAGS:
value->u8 = flow->nsh.flags;
break;
case MFF_NSH_TTL:
value->u8 = flow->nsh.ttl;
break;
case MFF_NSH_MDTYPE:
value->u8 = flow->nsh.mdtype;
break;
case MFF_NSH_NP:
value->u8 = flow->nsh.np;
break;
case MFF_NSH_SPI:
value->be32 = nsh_path_hdr_to_spi(flow->nsh.path_hdr);
if (value->be32 == htonl(NSH_SPI_MASK >> NSH_SPI_SHIFT)) {
value->be32 = OVS_BE32_MAX;
}
break;
case MFF_NSH_SI:
value->u8 = nsh_path_hdr_to_si(flow->nsh.path_hdr);
break;
case MFF_NSH_C1:
case MFF_NSH_C2:
case MFF_NSH_C3:
case MFF_NSH_C4:
value->be32 = flow->nsh.context[mf->id - MFF_NSH_C1];
break;
case MFF_N_IDS:
default:
OVS_NOT_REACHED();
}
}
/* Makes 'match' match field 'mf' exactly, with the value matched taken from
* 'value'. The caller is responsible for ensuring that 'match' meets 'mf''s
* prerequisites.
*
* If non-NULL, 'err_str' returns a malloc'ed string describing any errors
* with the request or NULL if there is no error. The caller is reponsible
* for freeing the string. */
void
mf_set_value(const struct mf_field *mf,
const union mf_value *value, struct match *match, char **err_str)
{
if (err_str) {
*err_str = NULL;
}