Skip to content

Commit 5497084

Browse files
authored
NETOBSERV-1890: read TCP flags as strings (#632)
* NETOBSERV-1890: read TCP flags as strings * Use flags list * Add TCPFlags to list of arrays * fix lint
1 parent 765ca7c commit 5497084

File tree

6 files changed

+26
-51
lines changed

6 files changed

+26
-51
lines changed

pkg/model/fields/fields.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ func IsNumeric(v string) bool {
6969
Packets,
7070
Proto,
7171
Bytes,
72-
DSCP,
73-
TCPFlags:
72+
DSCP:
7473
return true
7574
default:
7675
return false
@@ -95,7 +94,8 @@ func IsArray(v string) bool {
9594
case
9695
IfDirections,
9796
Interfaces,
98-
NetworkEvents:
97+
NetworkEvents,
98+
TCPFlags:
9999
return true
100100
default:
101101
return false

web/src/api/ipfix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export interface Fields {
118118
/** Network Events */
119119
NetworkEvents?: string[];
120120
/** Logical OR combination of unique TCP flags comprised in the flow, as per RFC-9293, with additional custom flags to represent the following per-packet combinations: SYN+ACK (0x100), FIN+ACK (0x200) and RST+ACK (0x400). */
121-
Flags?: number;
121+
Flags?: string[];
122122
/** Number of packets */
123123
Packets?: number;
124124
/** In conversation tracking, A to B packets counter per conversation */

web/src/components/drawer/record/record-field.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getICMPCode, getICMPDocUrl, getICMPType, icmpAllTypesValues, isValidICM
1414
import { dropCausesNames, getDropCauseDescription, getDropCauseDocUrl } from '../../../utils/pkt-drop';
1515
import { formatPort } from '../../../utils/port';
1616
import { formatProtocol, getProtocolDocUrl } from '../../../utils/protocol';
17-
import { decomposeTCPFlagsBitfield, getTCPFlagsDocUrl } from '../../../utils/tcp-flags';
17+
import { getFlagsList, getTCPFlagsDocUrl } from '../../../utils/tcp-flags';
1818
import { Size } from '../../dropdowns/table-display-dropdown';
1919
import './record-field.css';
2020

@@ -340,9 +340,9 @@ export const RecordField: React.FC<RecordFieldProps> = ({
340340
}
341341
case ColumnsId.tcpflags: {
342342
let child = emptyText();
343-
if (typeof value === 'number' && !isNaN(value)) {
344-
const flags = decomposeTCPFlagsBitfield(value);
345-
const name = flags.length > 0 ? flags.map(f => f.name).join(', ') : String(value);
343+
if (Array.isArray(value) && value.length > 0) {
344+
const flags = getFlagsList(value as string[]);
345+
const joined = value.join(', ');
346346
if (detailed) {
347347
let description = `${t('Value')}: ${value}`;
348348
if (flags.length === 1) {
@@ -353,9 +353,9 @@ export const RecordField: React.FC<RecordFieldProps> = ({
353353
t('The flow contains packets with various flags: ') +
354354
flags.map(f => f.name + ' (' + f.description + ')').join('; ');
355355
}
356-
child = clickableContent(name, description, getTCPFlagsDocUrl());
356+
child = clickableContent(joined, description, getTCPFlagsDocUrl());
357357
} else {
358-
child = simpleTextWithTooltip(name)!;
358+
child = simpleTextWithTooltip(joined)!;
359359
}
360360
}
361361
return singleContainer(child);

web/src/utils/__tests__/tcp-flags.spec.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

web/src/utils/filter-options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ export const getDSCPOptions = (value: string): Promise<FilterOption[]> => {
174174
export const getTCPFlagsOptions = (value: string): Promise<FilterOption[]> => {
175175
return Promise.resolve(
176176
tcpFlagsList
177-
.filter(opt => String(opt.value).includes(value) || opt.name.toLowerCase().includes(value.toLowerCase()))
178-
.map(v => ({ name: v.name, value: String(v.value) }))
177+
.filter(opt => opt.name.toLowerCase().includes(value.toLowerCase()))
178+
.map(v => ({ name: v.name, value: v.name }))
179179
);
180180
};
181181

web/src/utils/tcp-flags.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
1-
import { ReadOnlyValue, ReadOnlyValues } from './values';
2-
31
export const getTCPFlagsDocUrl = () => {
42
return 'https://www.rfc-editor.org/rfc/rfc9293';
53
};
64

7-
export const tcpFlagsList: ReadOnlyValues = [
8-
{ value: 1, name: 'FIN', description: 'No more data from sender' },
9-
{ value: 2, name: 'SYN', description: 'Synchronize sequence numbers' },
10-
{ value: 4, name: 'RST', description: 'Reset the connection' },
11-
{ value: 8, name: 'PSH', description: 'Push function' },
12-
{ value: 16, name: 'ACK', description: 'Acknowledgement field is significant' },
13-
{ value: 32, name: 'URG', description: 'Urgent pointer field is significant' },
14-
{ value: 64, name: 'ECE', description: 'ECN-Echo' },
15-
{ value: 128, name: 'CWR', description: 'Congestion Window Reduced' },
16-
{ value: 256, name: 'SYN_ACK', description: 'Acknowledgement of SYN (custom flag)' },
17-
{ value: 512, name: 'FIN_ACK', description: 'Acknowledgement of FIN (custom flag)' },
18-
{ value: 1024, name: 'RST_ACK', description: 'Acknowledgement of RST (custom flag)' }
5+
export const tcpFlagsList = [
6+
{ name: 'FIN', description: 'No more data from sender' },
7+
{ name: 'SYN', description: 'Synchronize sequence numbers' },
8+
{ name: 'RST', description: 'Reset the connection' },
9+
{ name: 'PSH', description: 'Push function' },
10+
{ name: 'ACK', description: 'Acknowledgement field is significant' },
11+
{ name: 'URG', description: 'Urgent pointer field is significant' },
12+
{ name: 'ECE', description: 'ECN-Echo' },
13+
{ name: 'CWR', description: 'Congestion Window Reduced' },
14+
{ name: 'SYN_ACK', description: 'Acknowledgement of SYN (custom flag)' },
15+
{ name: 'FIN_ACK', description: 'Acknowledgement of FIN (custom flag)' },
16+
{ name: 'RST_ACK', description: 'Acknowledgement of RST (custom flag)' }
1917
] as const;
2018

21-
export const decomposeTCPFlagsBitfield = (bitfield: number): ReadOnlyValues => {
22-
const values: ReadOnlyValue[] = [];
23-
tcpFlagsList.forEach(flag => {
24-
if (bitfield & flag.value) {
25-
values.push(flag);
26-
}
27-
});
28-
return values;
19+
export const getFlagsList = (names: string[]): { name: string; description: string }[] => {
20+
return tcpFlagsList.filter(f => names.includes(f.name));
2921
};

0 commit comments

Comments
 (0)