Skip to content

Commit b1100bf

Browse files
authored
Merge pull request #247 from Nordix/flow-match
Add Byte Matches support in Flows
2 parents d2fcb46 + de1e7ba commit b1100bf

File tree

7 files changed

+127
-78
lines changed

7 files changed

+127
-78
lines changed

api/nsp/v1/model.pb.go

+87-76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/nsp/v1/model.proto

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ message Flow {
6060
repeated Vip vips = 8;
6161
// The port that the application listens on, or 0 if not used
6262
uint32 localPort = 9;
63+
// Bytes in L4 header
64+
repeated string byteMatches = 10;
6365
}
6466

6567
message Vip {

api/nsp/v1/utils.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ func (f *Flow) DeepEquals(f2 *Flow) bool {
134134
compareSlice(f.GetProtocols(), f2.GetProtocols()) &&
135135
compareSlice(f.GetSourcePortRanges(), f2.GetSourcePortRanges()) &&
136136
compareSlice(f.GetSourceSubnets(), f2.GetSourceSubnets()) &&
137-
compareSlice(vipsToSlice(f.GetVips()), vipsToSlice(f2.GetVips()))
137+
compareSlice(vipsToSlice(f.GetVips()), vipsToSlice(f2.GetVips())) &&
138+
compareSlice(f.GetByteMatches(), f2.GetByteMatches())
138139
}
139140

140141
// compareSlice -

pkg/configuration/reader/converter.go

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func ConvertFlows(flows []*Flow, streams []*nspAPI.Stream, vips []*nspAPI.Vip) [
110110
Stream: s,
111111
Vips: getVips(flow.Vips, vips),
112112
LocalPort: uint32(flow.LocalPort),
113+
ByteMatches: flow.ByteMatches,
113114
})
114115
}
115116
return resFlows

pkg/configuration/reader/model.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2021 Nordix Foundation
2+
Copyright (c) 2021-2022 Nordix Foundation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -52,6 +52,7 @@ type Flow struct {
5252
Priority int32 `yaml:"priority"`
5353
Stream string `yaml:"stream"`
5454
LocalPort uint16 `yaml:"local-port,omitempty"`
55+
ByteMatches []string `yaml:"byte-matches,omitempty"`
5556
}
5657

5758
type VipList struct {
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright (c) 2022 Nordix Foundation
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package reader
18+
19+
import (
20+
"regexp"
21+
)
22+
23+
const (
24+
ByteMatchPattern = `^(sctp|tcp|udp)\[[0-9]+ *: *[124]\]( *& *0x[0-9a-f]+)? *= *([0-9]+|0x[0-9a-f]+)$`
25+
)
26+
27+
func ValidByteMatch(byteMatch string) bool {
28+
res, _ := regexp.MatchString(ByteMatchPattern, byteMatch)
29+
return res
30+
}

pkg/loadbalancer/nfqlb/nfqlb.go

+3
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ func (n *nfqlb) SetFlow(flow *nspAPI.Flow) error {
244244
if sports := flow.GetSourcePortRanges(); sports != nil && !n.anyPortRange(sports) {
245245
args = append(args, fmt.Sprintf("--sports=%v", strings.Join(sports, ",")))
246246
}
247+
if byteMatches := flow.GetByteMatches(); byteMatches != nil {
248+
args = append(args, fmt.Sprintf("--match=%v", strings.Join(byteMatches, ",")))
249+
}
247250

248251
cmd := exec.CommandContext(
249252
ctx,

0 commit comments

Comments
 (0)