Skip to content

Commit f7ca904

Browse files
committed
ovs: correctly parse port only resubmit
1 parent 3ac8368 commit f7ca904

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

ovs/action.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ const (
149149
patModTransportSourcePort = "mod_tp_src:%d"
150150
patModVLANVID = "mod_vlan_vid:%d"
151151
patOutput = "output:%d"
152-
patResubmit = "resubmit(%s,%s)"
152+
patResubmitPort = "resubmit:%s"
153+
patResubmitPortTable = "resubmit(%s,%s)"
153154
)
154155

155156
// ConnectionTracking sends a packet through the host's connection tracker.
@@ -398,9 +399,10 @@ func (a *resubmitAction) MarshalText() ([]byte, error) {
398399
t := ""
399400
if a.table != 0 {
400401
t = strconv.Itoa(a.table)
402+
return bprintf(patResubmitPortTable, p, t), nil
401403
}
402404

403-
return bprintf(patResubmit, p, t), nil
405+
return bprintf(patResubmitPort, p), nil
404406
}
405407

406408
// GoString implements Action.

ovs/action_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func TestActionResubmit(t *testing.T) {
344344
{
345345
desc: "table zero",
346346
port: 1,
347-
action: "resubmit(1,)",
347+
action: "resubmit:1",
348348
},
349349
{
350350
desc: "both port and table non-zero",

ovs/actionparser.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (s *stack) pop() {
146146
var (
147147
// resubmitRe is the regex used to match the resubmit action
148148
// with one or more of its parameters.
149-
resubmitRe = regexp.MustCompile(`resubmit\((\d*),(\d*)\)`)
149+
resubmitRe = regexp.MustCompile(`resubmit(?::(\d+)|\((\d*),(\d*)\))`)
150150

151151
// ctRe is the regex used to match the ct action with its
152152
// parameter list.
@@ -306,7 +306,7 @@ func parseAction(s string) (Action, error) {
306306
}
307307

308308
// ActionResubmit, with one or both of port number and table number
309-
if ss := resubmitRe.FindAllStringSubmatch(s, 2); len(ss) > 0 && len(ss[0]) == 3 {
309+
if ss := resubmitRe.FindAllStringSubmatch(s, 1); len(ss) > 0 && len(ss[0]) == 4 {
310310
var (
311311
port int
312312
table int
@@ -316,16 +316,26 @@ func parseAction(s string) (Action, error) {
316316

317317
// Results are:
318318
// - full string
319-
// - port
320-
// - table
319+
// - single port
320+
// - port in parenthesis
321+
// - table in parenthesis
322+
321323
if s := ss[0][1]; s != "" {
322324
port, err = strconv.Atoi(s)
323325
if err != nil {
324326
return nil, err
325327
}
328+
return Resubmit(port, 0), nil
326329
}
330+
327331
if s := ss[0][2]; s != "" {
328-
table, err = strconv.Atoi(ss[0][2])
332+
port, err = strconv.Atoi(s)
333+
if err != nil {
334+
return nil, err
335+
}
336+
}
337+
if s := ss[0][3]; s != "" {
338+
table, err = strconv.Atoi(s)
329339
if err != nil {
330340
return nil, err
331341
}

ovs/actionparser_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func Test_parseAction(t *testing.T) {
9393
var tests = []struct {
9494
desc string
9595
s string
96+
final string
9697
a Action
9798
invalid bool
9899
}{
@@ -237,8 +238,13 @@ func Test_parseAction(t *testing.T) {
237238
invalid: true,
238239
},
239240
{
240-
s: "resubmit(1,)",
241-
a: Resubmit(1, 0),
241+
s: "resubmit:4",
242+
a: Resubmit(4, 0),
243+
},
244+
{
245+
s: "resubmit(1,)",
246+
final: "resubmit:1",
247+
a: Resubmit(1, 0),
242248
},
243249
{
244250
s: "resubmit(,2)",
@@ -302,6 +308,10 @@ func Test_parseAction(t *testing.T) {
302308
want = strings.ToLower(want)
303309
}
304310

311+
if tt.final != "" {
312+
want = tt.final
313+
}
314+
305315
if got := string(s); want != got {
306316
t.Fatalf("unexpected action:\n- want: %q\n- got: %q",
307317
want, got)

0 commit comments

Comments
 (0)