Skip to content

Commit

Permalink
Omit zero srcPort / dstPort in Traceflow requests from web client (an…
Browse files Browse the repository at this point in the history
…trea-io#361)

Starting with v1beta1 of the Traceflow API, it is invalid to explicitly
set srcPort / dstPort to 0. 0 is not a valid port value in general, and
the UI uses 0 for some special cases (e.g., to tell the server to use a
random srcPort for a Traceflow request).

Signed-off-by: Antonin Bas <[email protected]>
  • Loading branch information
antoninbas committed May 10, 2024
1 parent d0964b6 commit 64b102f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 1 addition & 5 deletions client/web/antrea-ui/src/routes/traceflow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ describe('Traceflow request', () => {
},
transportHeader: {
tcp: {
srcPort: 0,
dstPort: 80,
flags: 2,
},
Expand Down Expand Up @@ -239,10 +238,7 @@ describe('Traceflow request', () => {
protocol: 17,
},
transportHeader: {
udp: {
srcPort: 0,
dstPort: 0,
},
udp: {},
},
},
liveTraffic: true,
Expand Down
21 changes: 15 additions & 6 deletions client/web/antrea-ui/src/routes/traceflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,27 @@ function createTraceflowPacket(inputs: Inputs, useIPv6: boolean): TraceflowPacke
case "TCP": {
protocol = 6;
packet.transportHeader.tcp = {
srcPort: inputs.srcPort,
dstPort: inputs.dstPort,
flags: inputs.tcpFlags,
};
// A srcPort or dstPort equal to 0 (which has a specific meaning) must be omitted
// from the Traceflow API request (since v1beta1), or the request will be rejected.
if (inputs.srcPort > 0) {
packet.transportHeader.tcp.srcPort = inputs.srcPort;
}
if (inputs.dstPort > 0) {
packet.transportHeader.tcp.dstPort = inputs.dstPort;
}
break;
}
case "UDP": {
protocol = 17;
packet.transportHeader.udp = {
srcPort: inputs.srcPort,
dstPort: inputs.dstPort,
};
packet.transportHeader.udp = {};
if (inputs.srcPort > 0) {
packet.transportHeader.udp.srcPort = inputs.srcPort;
}
if (inputs.dstPort > 0) {
packet.transportHeader.udp.dstPort = inputs.dstPort;
}
break;
}
}
Expand Down

0 comments on commit 64b102f

Please sign in to comment.