Commit db87d6ee authored by Jan Maria Matejka's avatar Jan Maria Matejka
Browse files

Protocol: Introducing an enum protocol_class

This supersedes the EAP_* constants.
parent 341315ab
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1508,7 +1508,7 @@ interpret(struct f_inst *what)

      /* We ignore temporary attributes, probably not a problem here */
      /* 0x02 is a value of BA_AS_PATH, we don't want to include BGP headers */
      eattr *e = ea_find((*f_rte)->attrs->eattrs, EA_CODE(EAP_BGP, 0x02));
      eattr *e = ea_find((*f_rte)->attrs->eattrs, EA_CODE(PROTOCOL_BGP, 0x02));

      if (!e || e->type != EAF_TYPE_AS_PATH)
	runtime("Missing AS_PATH attribute");
+4 −5
Original line number Diff line number Diff line
@@ -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 */
+20 −1
Original line number Diff line number Diff line
@@ -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 */
+2 −14
Original line number Diff line number Diff line
@@ -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
 */
+1 −4
Original line number Diff line number Diff line
@@ -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)
Loading