Skip to content

Commit d5c96b1

Browse files
Merge pull request #68 from digitalocean/kshanmugam/ovs-icmp6
Added ICMPv6 code and type to OVS match
2 parents d4914fa + bdadc6a commit d5c96b1

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

ovs/match.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ const (
5050
dlVLAN = "dl_vlan"
5151
dlVLANPCP = "dl_vlan_pcp"
5252
icmpType = "icmp_type"
53+
icmpCode = "icmp_code"
54+
icmp6Type = "icmpv6_type"
55+
icmp6Code = "icmpv6_code"
5356
ipv6DST = "ipv6_dst"
5457
ipv6SRC = "ipv6_src"
5558
ipv6Label = "ipv6_label"
@@ -469,6 +472,78 @@ func (m *icmpTypeMatch) GoString() string {
469472
return fmt.Sprintf("ovs.ICMPType(%d)", m.typ)
470473
}
471474

475+
// ICMPCode matches packets with the specified ICMP code
476+
func ICMPCode(code uint8) Match {
477+
return &icmpCodeMatch{
478+
code: code,
479+
}
480+
}
481+
482+
var _ Match = &icmpCodeMatch{}
483+
484+
// An icmpCodeMatch is a Match returned by ICMPCode
485+
type icmpCodeMatch struct {
486+
code uint8
487+
}
488+
489+
// MarshalText implements Match.
490+
func (m *icmpCodeMatch) MarshalText() ([]byte, error) {
491+
return bprintf("%s=%d", icmpCode, m.code), nil
492+
}
493+
494+
// GoString implements Match.
495+
func (m *icmpCodeMatch) GoString() string {
496+
return fmt.Sprintf("ovs.ICMPCode(%d)", m.code)
497+
}
498+
499+
// ICMP6Type matches packets with the specified ICMP type matching typ.
500+
func ICMP6Type(typ uint8) Match {
501+
return &icmp6TypeMatch{
502+
typ: typ,
503+
}
504+
}
505+
506+
var _ Match = &icmp6TypeMatch{}
507+
508+
// An icmpTypeMatch is a Match returned by ICMPType.
509+
type icmp6TypeMatch struct {
510+
typ uint8
511+
}
512+
513+
// MarshalText implements Match.
514+
func (m *icmp6TypeMatch) MarshalText() ([]byte, error) {
515+
return bprintf("%s=%d", icmp6Type, m.typ), nil
516+
}
517+
518+
// GoString implements Match.
519+
func (m *icmp6TypeMatch) GoString() string {
520+
return fmt.Sprintf("ovs.ICMP6Type(%d)", m.typ)
521+
}
522+
523+
// ICMP6Code matches packets with the specified ICMP type matching typ.
524+
func ICMP6Code(code uint8) Match {
525+
return &icmp6CodeMatch{
526+
code: code,
527+
}
528+
}
529+
530+
var _ Match = &icmp6CodeMatch{}
531+
532+
// An icmpCodeMatch is a Match returned by ICMP6Code
533+
type icmp6CodeMatch struct {
534+
code uint8
535+
}
536+
537+
// MarshalText implements Match.
538+
func (m *icmp6CodeMatch) MarshalText() ([]byte, error) {
539+
return bprintf("%s=%d", icmp6Code, m.code), nil
540+
}
541+
542+
// GoString implements Match.
543+
func (m *icmp6CodeMatch) GoString() string {
544+
return fmt.Sprintf("ovs.ICMP6Code(%d)", m.code)
545+
}
546+
472547
// InPortMatch matches packets ingressing from a specified OVS port
473548
func InPortMatch(port int) Match {
474549
return &inPortMatch{

ovs/matchparser.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func parseMatch(key string, value string) (Match, error) {
3131
return parseMACMatch(key, value)
3232
case arpOp:
3333
return parseArpOp(value)
34-
case icmpType, nwProto:
34+
case icmpType, icmpCode, icmp6Type, icmp6Code, nwProto:
3535
return parseIntMatch(key, value, math.MaxUint8)
3636
case ctZone:
3737
return parseIntMatch(key, value, math.MaxUint16)
@@ -120,6 +120,12 @@ func parseIntMatch(key string, value string, max int) (Match, error) {
120120
switch key {
121121
case icmpType:
122122
return ICMPType(uint8(t)), nil
123+
case icmpCode:
124+
return ICMPCode(uint8(t)), nil
125+
case icmp6Type:
126+
return ICMP6Type(uint8(t)), nil
127+
case icmp6Code:
128+
return ICMP6Code(uint8(t)), nil
123129
case inPort:
124130
return InPortMatch(int(t)), nil
125131
case nwECN:

ovs/matchparser_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ func Test_parseMatch(t *testing.T) {
135135
s: "icmp_type=1",
136136
m: ICMPType(1),
137137
},
138+
{
139+
s: "icmp_code=1",
140+
m: ICMPCode(1),
141+
},
138142
{
139143
s: "ipv6_src=2001:db8::1",
140144
m: IPv6Source("2001:db8::1"),
@@ -143,6 +147,14 @@ func Test_parseMatch(t *testing.T) {
143147
s: "ipv6_dst=2001:db8::1",
144148
m: IPv6Destination("2001:db8::1"),
145149
},
150+
{
151+
s: "icmpv6_type=135",
152+
m: ICMP6Type(135),
153+
},
154+
{
155+
s: "icmpv6_code=0",
156+
m: ICMP6Code(0),
157+
},
146158
{
147159
s: "nd_sll=foo",
148160
invalid: true,

ovsnl/datapath.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (s *DatapathService) List() ([]Datapath, error) {
109109
}),
110110
}
111111

112-
flags := netlink.HeaderFlagsRequest | netlink.HeaderFlagsDump
112+
flags := netlink.Request | netlink.Dump
113113
msgs, err := s.c.c.Execute(req, s.f.ID, flags)
114114
if err != nil {
115115
return nil, err

0 commit comments

Comments
 (0)