File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ const (
35
35
36
36
// Constants of full Match names.
37
37
const (
38
+ arpOp = "arp_op"
38
39
arpSHA = "arp_sha"
39
40
arpSPA = "arp_spa"
40
41
arpTHA = "arp_tha"
@@ -433,6 +434,30 @@ func (m *neighborDiscoveryLinkLayerMatch) GoString() string {
433
434
return fmt .Sprintf ("ovs.NeighborDiscoveryTargetLinkLayer(%s)" , syntax )
434
435
}
435
436
437
+ // ARPOperation matches packets with the specified ARP operation matching oper.
438
+ func ARPOperation (oper uint16 ) Match {
439
+ return & arpOperationMatch {
440
+ oper : oper ,
441
+ }
442
+ }
443
+
444
+ var _ Match = & arpOperationMatch {}
445
+
446
+ // An arpOperationMatch is a Match returned by ARPOperation.
447
+ type arpOperationMatch struct {
448
+ oper uint16
449
+ }
450
+
451
+ // MarshalText implements Match.
452
+ func (m * arpOperationMatch ) MarshalText () ([]byte , error ) {
453
+ return bprintf ("%s=%d" , arpOp , m .oper ), nil
454
+ }
455
+
456
+ // GoString implements Match.
457
+ func (m * arpOperationMatch ) GoString () string {
458
+ return fmt .Sprintf ("ovs.ARPOperation(%d)" , m .oper )
459
+ }
460
+
436
461
// ARPSourceHardwareAddress matches packets with an ARP source hardware address
437
462
// (SHA) matching addr.
438
463
func ARPSourceHardwareAddress (addr net.HardwareAddr ) Match {
Original file line number Diff line number Diff line change @@ -1035,6 +1035,10 @@ func TestMatchGoString(t *testing.T) {
1035
1035
m : ConjunctionID (123 ),
1036
1036
s : `ovs.ConjunctionID(123)` ,
1037
1037
},
1038
+ {
1039
+ m : ARPOperation (2 ),
1040
+ s : `ovs.ARPOperation(2)` ,
1041
+ },
1038
1042
}
1039
1043
1040
1044
for _ , tt := range tests {
@@ -1046,6 +1050,39 @@ func TestMatchGoString(t *testing.T) {
1046
1050
}
1047
1051
}
1048
1052
1053
+ func TestMatchARPOperation (t * testing.T ) {
1054
+ var tests = []struct {
1055
+ desc string
1056
+ oper uint16
1057
+ out string
1058
+ }{
1059
+ {
1060
+ desc : "request" ,
1061
+ oper : 1 ,
1062
+ out : "arp_op=1" ,
1063
+ },
1064
+ {
1065
+ desc : "response" ,
1066
+ oper : 2 ,
1067
+ out : "arp_op=2" ,
1068
+ },
1069
+ }
1070
+
1071
+ for _ , tt := range tests {
1072
+ t .Run (tt .desc , func (t * testing.T ) {
1073
+ out , err := ARPOperation (tt .oper ).MarshalText ()
1074
+ if err != nil {
1075
+ t .Fatalf ("unexpected error: %v" , err )
1076
+ }
1077
+
1078
+ if want , got := tt .out , string (out ); want != got {
1079
+ t .Fatalf ("unexpected Match output:\n - want: %q\n - got: %q" ,
1080
+ want , got )
1081
+ }
1082
+ })
1083
+ }
1084
+ }
1085
+
1049
1086
// mustParseMAC is a helper to parse a hardware address from a string using
1050
1087
// net.ParseMAC, that panic on failure.
1051
1088
func mustParseMAC (addr string ) net.HardwareAddr {
You can’t perform that action at this time.
0 commit comments