Skip to content

Commit

Permalink
Allow filtering based on TCPFlags values
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <mmahmoud@redhat.com>
  • Loading branch information
msherif1234 committed Jul 11, 2024
1 parent 3d6a89a commit 197fbdf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/model/fields/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
DNSCode = "DnsFlagsResponseCode"
Duplicate = "Duplicate"
TimeFlowRTT = "TimeFlowRttNs"
TCPFlags = "Flags"
)

func IsNumeric(v string) bool {
Expand All @@ -67,7 +68,8 @@ func IsNumeric(v string) bool {
Packets,
Proto,
Bytes,
DSCP:
DSCP,
TCPFlags:
return true
default:
return false
Expand Down
4 changes: 4 additions & 0 deletions web/src/utils/filter-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
getPortOptions,
getProtocolOptions,
getResourceOptions,
getTCPFlagsOptions,
getZoneOptions,
noOption
} from './filter-options';
Expand Down Expand Up @@ -299,7 +300,10 @@ export const getFilterDefinitions = (
getOptions = getDnsErrorCodeOptions;
} else if (d.id.includes('dscp')) {
getOptions = getDSCPOptions;
} else if (d.id.includes('flags')) {
getOptions = getTCPFlagsOptions;
}

return { getOptions, validate, encoder, checkCompletion };
};

Expand Down
9 changes: 9 additions & 0 deletions web/src/utils/filter-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { dnsErrors, dnsRCodes } from './dns';
import { DSCP_VALUES } from './dscp';
import { dropCauses, dropStates } from './pkt-drop';
import { getPort, getService } from './port';
import { TCPFlags_VALUES } from './tcp_flags';

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

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

export const getTCPFlagsOptions = (value: string): Promise<FilterOption[]> => {
return Promise.resolve(
TCPFlags_VALUES.filter(
opt => String(opt.value).includes(value) || opt.name.toLowerCase().includes(value.toLowerCase())
).map(v => ({ name: v.name, value: String(v.value) }))
);
};

export const findProtocolOption = (nameOrVal: string) => {
return protocolOptions.find(p => p.name.toLowerCase() === nameOrVal.toLowerCase() || p.value === nameOrVal);
};
Expand Down
33 changes: 33 additions & 0 deletions web/src/utils/tcp_flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ReadOnlyValues } from './values';

export const getTCPFlagsDocUrl = () => {
return 'https://www.rfc-editor.org/rfc/rfc9293';
};

export const TCPFlags_VALUES: ReadOnlyValues = [
{ value: 1, name: 'FIN', description: 'No more data from sender' },
{ value: 2, name: 'SYN', description: 'Synchronize sequence numbers' },
{ value: 4, name: 'RST', description: 'Reset the connection' },
{ value: 8, name: 'PSH', description: 'Push function' },
{ value: 16, name: 'ACK', description: 'Acknowledgement field is significant' },
{ value: 32, name: 'URG', description: 'Urgent pointer field is significant' },
{ value: 64, name: 'ECE', description: 'ECN-Echo' },
{ value: 128, name: 'CWR', description: 'Congestion Window Reduced' },
{ value: 256, name: 'SYN_ACK', description: 'Custom flag indicating both SYN and ACK flags are set' },
{ value: 512, name: 'FIN_ACK', description: 'Custom flag indicating both FIN and ACK flags are set' },
{ value: 1024, name: 'RST_ACK', description: 'Custom flag indicating both RST and ACK flags are set' }
] as const;

const tcpFlagsNames = TCPFlags_VALUES.map(v => v.name);
export type TCPFLAGS_SERVICE_CLASS_NAMES = typeof tcpFlagsNames[number];

export const gettcpFlagsServiceClassName = (flags: number): TCPFLAGS_SERVICE_CLASS_NAMES | undefined => {
return TCPFlags_VALUES.find(v => v.value === flags)?.name;
};

const tcpFlagsDescriptions = TCPFlags_VALUES.map(v => v.description);
export type TCPFLAGS_SERVICE_CLASS_DESCRIPTIONS = typeof tcpFlagsDescriptions[number];

export const gettcpFlagsServiceClassDescription = (flags: number): TCPFLAGS_SERVICE_CLASS_DESCRIPTIONS | undefined => {
return TCPFlags_VALUES.find(v => v.value === flags)?.description;
};

0 comments on commit 197fbdf

Please sign in to comment.