Repository navigation
Expand file tree
/
Copy pathprotocol.h
More file actions
114 lines (94 loc) · 3.5 KB
/
Copy pathprotocol.h
File metadata and controls
114 lines (94 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) 2023-2025, Ericsson AB and Ericsson Telecommunication Hungary
// All rights reserved.
#ifndef DNT_PROTOCOL_H
#define DNT_PROTOCOL_H
#include <stdbool.h>
#include <stdint.h>
enum ProtocolFieldType {
PFTYPE_UNKNOWN,
PFTYPE_NUMBER,
PFTYPE_MACADDRESS,
PFTYPE_IPV4ADDRESS,
PFTYPE_IPV6ADDRESS,
PFTYPE_TSNSEQ,
PFTYPE_SRV6SEQ,
PFTYPE_TSNTSTAMP,
PFTYPE_TTL,
PFTYPE_CHECKSUM,
PFTYPE_NEXTHEADER,
};
// the internal id of the protocols is their index in the @protocol_list array
//TODO autogenerate this list
enum ProtocolID {
PROTO_ID_PAYLOAD,
PROTO_ID_ETH,
PROTO_ID_SVLAN,
PROTO_ID_CVLAN,
PROTO_ID_RTAG,
PROTO_ID_TTAG,
PROTO_ID_MPLS,
PROTO_ID_DCW,
PROTO_ID_TCW,
PROTO_ID_IPv4,
PROTO_ID_IPv6,
PROTO_ID_ARP,
PROTO_ID_UDP,
PROTO_ID_TCP,
PROTO_ID_OAM, //TODO rename to OAMDCW or DACH
PROTO_ID_OAMRTAG,
PROTO_ID_CFM,
PROTO_ID_ICMPv4,
PROTO_ID_ICMPv6,
};
// describes one field of a protocol header
struct ProtocolField {
const char *name;
unsigned bitoffset;
unsigned bitcount;
enum ProtocolFieldType type;
};
/*TODO nexthdr<-->id conversion problem:
* the API is tailored for Ethernet family, IP family has 8 bits
* config compiler can know about this and set the field appropriately...
*/
// @returns false on error
// @nexthdr is in host byte order
typedef bool id_from_nexthdr(enum ProtocolID *id, uint16_t nexthdr);
// @returns false on error
// @returns @nexthdr in host byte order
typedef bool nexthdr_from_id(uint16_t *nexthdr, enum ProtocolID id);
// describes one fixed-size protocol header
struct Protocol {
const char *name;
const struct ProtocolField *header_fields;
unsigned header_field_count;
unsigned bytelength;
id_from_nexthdr *get_id; // translates the value of the next header field to protocol id
nexthdr_from_id *get_nexthdr; // translates protocol id to next header field value
const char *default_value; // initialize newly created header with these bytes
unsigned default_value_len; // only initialize the first few octets
};
// @returns the protocol descriptor for the given @id
const struct Protocol *protocol_from_id(enum ProtocolID id);
// @returns the name of the field type or NULL on unknown type
const char *fieldtype_name_from_type(enum ProtocolFieldType type);
// @returns true if @type is a valid protocol name
bool protocol_type_valid(const char *type);
// @returns PROTO_ID_PAYLOAD for unknown protocol type
// use @protocol_type_valid to make sure that @type is valid
enum ProtocolID protocol_id_from_type(const char *type);
// @returns the type name of the given protocol
// @returns NULL if unknown id
const char *protocol_type_from_id(enum ProtocolID id);
// @returns pointer to the field descriptor
// @returns NULL if the protocol has no field with the given @fieldname
const struct ProtocolField *protocol_get_field_by_name(enum ProtocolID id, const char *fieldname);
// @returns true if @fieldname is valid for this protocol
bool protocol_fieldname_valid(enum ProtocolID id, const char *fieldname);
// @returns pointer to the field descriptor
// @returns NULL if the protocol has no field with the given @type
const struct ProtocolField *protocol_get_field_by_type(enum ProtocolID id, enum ProtocolFieldType type);
// @returns index of the field in the protocol header
// @returns -1 if the protocol has no field with the given @type
int protocol_get_field_idx_by_type(enum ProtocolID id, enum ProtocolFieldType type);
#endif // DNT_PROTOCOL_H