Skip to content

Commit ce7067e

Browse files
authored
NETOBSERV-1756 Allow filtering based on TCPFlags values (#554)
* Allow filtering based on TCPFlags values Signed-off-by: Mohamed Mahmoud <[email protected]> * Use string format in columns and details instead of intg Signed-off-by: Mohamed Mahmoud <[email protected]> --------- Signed-off-by: Mohamed Mahmoud <[email protected]>
1 parent 3b4285e commit ce7067e

File tree

6 files changed

+75
-1
lines changed

6 files changed

+75
-1
lines changed

pkg/model/fields/fields.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const (
5252
DNSCode = "DnsFlagsResponseCode"
5353
Duplicate = "Duplicate"
5454
TimeFlowRTT = "TimeFlowRttNs"
55+
TCPFlags = "Flags"
5556
)
5657

5758
func IsNumeric(v string) bool {
@@ -67,7 +68,8 @@ func IsNumeric(v string) bool {
6768
Packets,
6869
Proto,
6970
Bytes,
70-
DSCP:
71+
DSCP,
72+
TCPFlags:
7173
return true
7274
default:
7375
return false

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ 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 {
25+
getTCPFlagsDocUrl,
26+
gettcpFlagsServiceClassDescription,
27+
gettcpFlagsServiceClassName
28+
} from '../../../utils/tcp_flags';
2429
import { Size } from '../../dropdowns/table-display-dropdown';
2530
import './record-field.css';
2631

@@ -470,6 +475,22 @@ export const RecordField: React.FC<RecordFieldProps> = ({
470475
}
471476
return singleContainer(child);
472477
}
478+
case ColumnsId.tcpflags: {
479+
let child = emptyText();
480+
if (typeof value === 'number' && !isNaN(value)) {
481+
const serviceClassName = gettcpFlagsServiceClassName(value);
482+
if (serviceClassName && detailed) {
483+
child = clickableContent(
484+
serviceClassName,
485+
`${t('Value')}: ${value} ${t('Examples')}: ${gettcpFlagsServiceClassDescription(value)}`,
486+
getTCPFlagsDocUrl()
487+
);
488+
} else {
489+
child = simpleTextWithTooltip(serviceClassName || String(value))!;
490+
}
491+
}
492+
return singleContainer(child);
493+
}
473494
case ColumnsId.icmptype: {
474495
let child = emptyText();
475496
if (Array.isArray(value) && value.length) {

web/src/utils/columns.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export enum ColumnsId {
4242
icmptype = 'IcmpType',
4343
icmpcode = 'IcmpCode',
4444
dscp = 'Dscp',
45+
tcpflags = 'TCPFlags',
4546
bytes = 'Bytes',
4647
packets = 'Packets',
4748
owner = 'K8S_OwnerName',

web/src/utils/filter-definitions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
getPortOptions,
3030
getProtocolOptions,
3131
getResourceOptions,
32+
getTCPFlagsOptions,
3233
getZoneOptions,
3334
noOption
3435
} from './filter-options';
@@ -299,7 +300,10 @@ export const getFilterDefinitions = (
299300
getOptions = getDnsErrorCodeOptions;
300301
} else if (d.id.includes('dscp')) {
301302
getOptions = getDSCPOptions;
303+
} else if (d.id.includes('flags')) {
304+
getOptions = getTCPFlagsOptions;
302305
}
306+
303307
return { getOptions, validate, encoder, checkCompletion };
304308
};
305309

web/src/utils/filter-options.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { dnsErrors, dnsRCodes } from './dns';
1010
import { DSCP_VALUES } from './dscp';
1111
import { dropCauses, dropStates } from './pkt-drop';
1212
import { getPort, getService } from './port';
13+
import { TCPFlags_VALUES } from './tcp_flags';
1314

1415
export const noOption: (value: string) => Promise<FilterOption[]> = () => Promise.resolve([]);
1516

@@ -169,6 +170,14 @@ export const getDSCPOptions = (value: string): Promise<FilterOption[]> => {
169170
);
170171
};
171172

173+
export const getTCPFlagsOptions = (value: string): Promise<FilterOption[]> => {
174+
return Promise.resolve(
175+
TCPFlags_VALUES.filter(
176+
opt => String(opt.value).includes(value) || opt.name.toLowerCase().includes(value.toLowerCase())
177+
).map(v => ({ name: v.name, value: String(v.value) }))
178+
);
179+
};
180+
172181
export const findProtocolOption = (nameOrVal: string) => {
173182
return protocolOptions.find(p => p.name.toLowerCase() === nameOrVal.toLowerCase() || p.value === nameOrVal);
174183
};

web/src/utils/tcp_flags.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ReadOnlyValues } from './values';
2+
3+
export const getTCPFlagsDocUrl = () => {
4+
return 'https://www.rfc-editor.org/rfc/rfc9293';
5+
};
6+
7+
export const TCPFlags_VALUES: ReadOnlyValues = [
8+
{ value: 1, name: 'FIN', description: 'No more data from sender' },
9+
{ value: 2, name: 'SYN', description: 'Synchronize sequence numbers' },
10+
{ value: 3, name: 'FIN_SYN', description: 'Custom flag indicating both FIN and SYN flags are set' },
11+
{ value: 4, name: 'RST', description: 'Reset the connection' },
12+
{ value: 5, name: 'FIN_RST', description: 'Custom flag indicating both FIN and RST flags are set' },
13+
{ value: 6, name: 'SYN_RST', description: 'Custom flag indicating both SYN and RST flags are set' },
14+
{ value: 7, name: 'FIN_SYN_RST', description: 'Custom flag indicating FIN, SYN and RST flags are set' },
15+
{ value: 8, name: 'PSH', description: 'Push function' },
16+
{ value: 16, name: 'ACK', description: 'Acknowledgement field is significant' },
17+
{ value: 32, name: 'URG', description: 'Urgent pointer field is significant' },
18+
{ value: 64, name: 'ECE', description: 'ECN-Echo' },
19+
{ value: 128, name: 'CWR', description: 'Congestion Window Reduced' },
20+
{ value: 256, name: 'SYN_ACK', description: 'Custom flag indicating both SYN and ACK flags are set' },
21+
{ value: 512, name: 'FIN_ACK', description: 'Custom flag indicating both FIN and ACK flags are set' },
22+
{ value: 1024, name: 'RST_ACK', description: 'Custom flag indicating both RST and ACK flags are set' }
23+
] as const;
24+
25+
const tcpFlagsNames = TCPFlags_VALUES.map(v => v.name);
26+
export type TCPFLAGS_SERVICE_CLASS_NAMES = typeof tcpFlagsNames[number];
27+
28+
export const gettcpFlagsServiceClassName = (flags: number): TCPFLAGS_SERVICE_CLASS_NAMES | undefined => {
29+
return TCPFlags_VALUES.find(v => v.value === flags)?.name;
30+
};
31+
32+
const tcpFlagsDescriptions = TCPFlags_VALUES.map(v => v.description);
33+
export type TCPFLAGS_SERVICE_CLASS_DESCRIPTIONS = typeof tcpFlagsDescriptions[number];
34+
35+
export const gettcpFlagsServiceClassDescription = (flags: number): TCPFLAGS_SERVICE_CLASS_DESCRIPTIONS | undefined => {
36+
return TCPFlags_VALUES.find(v => v.value === flags)?.description;
37+
};

0 commit comments

Comments
 (0)