Skip to content

Commit 866485e

Browse files
committed
NETOBSERV-1890: read TCP flags as strings
1 parent f8abad2 commit 866485e

File tree

6 files changed

+34
-61
lines changed

6 files changed

+34
-61
lines changed

pkg/model/fields/fields.go

Lines changed: 1 addition & 2 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

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: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
import { dropCausesNames, getDropCauseDescription, getDropCauseDocUrl } from '../../../utils/pkt-drop';
2222
import { formatPort } from '../../../utils/port';
2323
import { formatProtocol, getProtocolDocUrl } from '../../../utils/protocol';
24-
import { decomposeTCPFlagsBitfield, getTCPFlagsDocUrl } from '../../../utils/tcp-flags';
24+
import { getFlagsList, getTCPFlagsDocUrl } from '../../../utils/tcp-flags';
2525
import { Size } from '../../dropdowns/table-display-dropdown';
2626
import './record-field.css';
2727

@@ -473,23 +473,21 @@ export const RecordField: React.FC<RecordFieldProps> = ({
473473
}
474474
case ColumnsId.tcpflags: {
475475
let child = emptyText();
476-
if (typeof value === 'number' && !isNaN(value)) {
477-
const flags = decomposeTCPFlagsBitfield(value);
478-
const name = flags.length > 0 ? flags.map(f => f.name).join(', ') : String(value);
479-
if (detailed) {
480-
let description = `${t('Value')}: ${value}`;
481-
if (flags.length === 1) {
482-
description += '. ' + flags[0].description;
483-
} else if (flags.length > 1) {
484-
description +=
485-
'. ' +
486-
t('The flow contains packets with various flags: ') +
487-
flags.map(f => f.name + ' (' + f.description + ')').join('; ');
488-
}
489-
child = clickableContent(name, description, getTCPFlagsDocUrl());
490-
} else {
491-
child = simpleTextWithTooltip(name)!;
476+
const sVal = String(value);
477+
const flags = getFlagsList(sVal);
478+
if (detailed) {
479+
let description = `${t('Value')}: ${value}`;
480+
if (flags.length === 1) {
481+
description += '. ' + flags[0].description;
482+
} else if (flags.length > 1) {
483+
description +=
484+
'. ' +
485+
t('The flow contains packets with various flags: ') +
486+
flags.map(f => f.name + ' (' + f.description + ')').join('; ');
492487
}
488+
child = clickableContent(sVal, description, getTCPFlagsDocUrl());
489+
} else {
490+
child = simpleTextWithTooltip(sVal)!;
493491
}
494492
return singleContainer(child);
495493
}

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: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
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 = (joined: string): { name: string, description: string}[] => {
20+
const names = joined.split(',');
21+
return tcpFlagsList.filter(f => names.includes(f.name));
2922
};

0 commit comments

Comments
 (0)