diff options
author | Jan Maria Matejka <mq@ucw.cz> | 2018-05-07 14:47:00 +0200 |
---|---|---|
committer | Jan Maria Matejka <mq@ucw.cz> | 2018-05-29 12:35:06 +0200 |
commit | ee7e2ffd265fd76dbc8c94d9c2d48da54c27ff76 (patch) | |
tree | 7460254b1bd105e5bc45937e2e00aaac7da4ccf7 /nest | |
parent | c3becfe1934da2dc2c0881a71eac8a26f810791f (diff) |
Protocol: Introducing an enum protocol_class
This supersedes the EAP_* constants.
Diffstat (limited to 'nest')
-rw-r--r-- | nest/proto.c | 9 | ||||
-rw-r--r-- | nest/protocol.h | 21 | ||||
-rw-r--r-- | nest/route.h | 16 | ||||
-rw-r--r-- | nest/rt-attr.c | 5 | ||||
-rw-r--r-- | nest/rt-dev.c | 1 |
5 files changed, 28 insertions, 24 deletions
diff --git a/nest/proto.c b/nest/proto.c index 15d6f4de..49f71304 100644 --- a/nest/proto.c +++ b/nest/proto.c @@ -25,6 +25,7 @@ pool *proto_pool; list proto_list; static list protocol_list; +struct protocol *class_to_protocol[PROTOCOL__MAX]; #define PD(pr, msg, args...) do { if (pr->debug & D_STATES) { log(L_TRACE "%s: " msg, pr->name , ## args); } } while(0) @@ -1256,11 +1257,9 @@ void proto_build(struct protocol *p) { add_tail(&protocol_list, &p->n); - if (p->attr_class) - { - ASSERT(!attr_class_to_protocol[p->attr_class]); - attr_class_to_protocol[p->attr_class] = p; - } + ASSERT(p->class); + ASSERT(!class_to_protocol[p->class]); + class_to_protocol[p->class] = p; } /* FIXME: convert this call to some protocol hook */ diff --git a/nest/protocol.h b/nest/protocol.h index 8a22d76b..d790e90e 100644 --- a/nest/protocol.h +++ b/nest/protocol.h @@ -37,12 +37,31 @@ struct symbol; * Routing Protocol */ +enum protocol_class { + PROTOCOL_NONE, + PROTOCOL_BABEL, + PROTOCOL_BFD, + PROTOCOL_BGP, + PROTOCOL_DEVICE, + PROTOCOL_DIRECT, + PROTOCOL_KERNEL, + PROTOCOL_OSPF, + PROTOCOL_PIPE, + PROTOCOL_RADV, + PROTOCOL_RIP, + PROTOCOL_RPKI, + PROTOCOL_STATIC, + PROTOCOL__MAX +}; + +extern struct protocol *class_to_protocol[PROTOCOL__MAX]; + struct protocol { node n; char *name; char *template; /* Template for automatic generation of names */ int name_counter; /* Counter for automatic name generation */ - int attr_class; /* Attribute class known to this protocol */ + enum protocol_class class; /* Machine readable protocol class */ uint preference; /* Default protocol preference */ uint channel_mask; /* Mask of accepted channel types (NB_*) */ uint proto_size; /* Size of protocol data structure */ diff --git a/nest/route.h b/nest/route.h index 79127519..1391b357 100644 --- a/nest/route.h +++ b/nest/route.h @@ -457,7 +457,7 @@ static inline int rte_is_reachable(rte *r) */ typedef struct eattr { - word id; /* EA_CODE(EAP_..., protocol-dependent ID) */ + word id; /* EA_CODE(PROTOCOL_..., protocol-dependent ID) */ byte flags; /* Protocol-dependent flags */ byte type; /* Attribute type and several flags (EAF_...) */ union { @@ -466,20 +466,11 @@ typedef struct eattr { } u; } eattr; -#define EAP_GENERIC 0 /* Generic attributes */ -#define EAP_BGP 1 /* BGP attributes */ -#define EAP_RIP 2 /* RIP */ -#define EAP_OSPF 3 /* OSPF */ -#define EAP_KRT 4 /* Kernel route attributes */ -#define EAP_BABEL 5 /* Babel attributes */ -#define EAP_RADV 6 /* Router advertisment attributes */ -#define EAP_MAX 7 - #define EA_CODE(proto,id) (((proto) << 8) | (id)) #define EA_PROTO(ea) ((ea) >> 8) #define EA_ID(ea) ((ea) & 0xff) -#define EA_GEN_IGP_METRIC EA_CODE(EAP_GENERIC, 0) +#define EA_GEN_IGP_METRIC EA_CODE(PROTOCOL_NONE, 0) #define EA_CODE_MASK 0xffff #define EA_ALLOW_UNDEF 0x10000 /* ea_find: allow EAF_TYPE_UNDEF */ @@ -656,9 +647,6 @@ rta_set_recursive_next_hop(rtable *dep, rta *a, rtable *tab, ip_addr gw, ip_addr static inline void rt_lock_hostentry(struct hostentry *he) { if (he) he->uc++; } static inline void rt_unlock_hostentry(struct hostentry *he) { if (he) he->uc--; } - -extern struct protocol *attr_class_to_protocol[EAP_MAX]; - /* * Default protocol preferences */ diff --git a/nest/rt-attr.c b/nest/rt-attr.c index 881687de..f92efc2e 100644 --- a/nest/rt-attr.c +++ b/nest/rt-attr.c @@ -88,9 +88,6 @@ static struct idm src_ids; static HASH(struct rte_src) src_hash; -struct protocol *attr_class_to_protocol[EAP_MAX]; - - static void rte_src_init(void) { @@ -851,7 +848,7 @@ ea_show(struct cli *c, eattr *e) byte buf[CLI_MSG_SIZE]; byte *pos = buf, *end = buf + sizeof(buf); - if (p = attr_class_to_protocol[EA_PROTO(e->id)]) + if (p = class_to_protocol[EA_PROTO(e->id)]) { pos += bsprintf(pos, "%s.", p->name); if (p->get_attr) diff --git a/nest/rt-dev.c b/nest/rt-dev.c index 66f458e7..61f025ce 100644 --- a/nest/rt-dev.c +++ b/nest/rt-dev.c @@ -185,6 +185,7 @@ dev_copy_config(struct proto_config *dest, struct proto_config *src) struct protocol proto_device = { .name = "Direct", .template = "direct%d", + .class = PROTOCOL_DIRECT, .preference = DEF_PREF_DIRECT, .channel_mask = NB_IP | NB_IP6_SADR, .proto_size = sizeof(struct rt_dev_proto), |