Annotation of embedaddon/bird/proto/babel/babel.h, revision 1.1

1.1     ! misho       1: /*
        !             2:  *     BIRD -- The Babel protocol
        !             3:  *
        !             4:  *     Copyright (c) 2015--2016 Toke Hoiland-Jorgensen
        !             5:  *
        !             6:  *     Can be freely distributed and used under the terms of the GNU GPL.
        !             7:  *
        !             8:  *     This file contains the data structures used by Babel.
        !             9:  */
        !            10: 
        !            11: #ifndef _BIRD_BABEL_H_
        !            12: #define _BIRD_BABEL_H_
        !            13: 
        !            14: #include "nest/bird.h"
        !            15: #include "nest/cli.h"
        !            16: #include "nest/iface.h"
        !            17: #include "nest/route.h"
        !            18: #include "nest/protocol.h"
        !            19: #include "nest/locks.h"
        !            20: #include "lib/resource.h"
        !            21: #include "lib/lists.h"
        !            22: #include "lib/socket.h"
        !            23: #include "lib/string.h"
        !            24: #include "lib/timer.h"
        !            25: 
        !            26: #ifndef IPV6
        !            27: #error "The Babel protocol only speaks IPv6"
        !            28: #endif
        !            29: 
        !            30: #define EA_BABEL_METRIC                EA_CODE(EAP_BABEL, 0)
        !            31: #define EA_BABEL_ROUTER_ID     EA_CODE(EAP_BABEL, 1)
        !            32: 
        !            33: #define BABEL_MAGIC            42
        !            34: #define BABEL_VERSION          2
        !            35: #define BABEL_PORT             6696
        !            36: #define BABEL_INFINITY         0xFFFF
        !            37: 
        !            38: 
        !            39: #define BABEL_HELLO_INTERVAL_WIRED     4       /* Default hello intervals in seconds */
        !            40: #define BABEL_HELLO_INTERVAL_WIRELESS  4
        !            41: #define BABEL_UPDATE_INTERVAL_FACTOR   4
        !            42: #define BABEL_IHU_INTERVAL_FACTOR      3
        !            43: #define BABEL_IHU_EXPIRY_FACTOR(X)     ((X)*3/2)       /* 1.5 */
        !            44: #define BABEL_HELLO_EXPIRY_FACTOR(X)   ((X)*3/2)       /* 1.5 */
        !            45: #define BABEL_ROUTE_EXPIRY_FACTOR(X)   ((X)*7/2)       /* 3.5 */
        !            46: #define BABEL_ROUTE_REFRESH_INTERVAL   2       /* Seconds before route expiry to send route request */
        !            47: #define BABEL_HOLD_TIME                        10      /* Expiry time for our own routes */
        !            48: #define BABEL_RXCOST_WIRED             96
        !            49: #define BABEL_RXCOST_WIRELESS          256
        !            50: #define BABEL_INITIAL_HOP_COUNT                255
        !            51: #define BABEL_MAX_SEND_INTERVAL                5
        !            52: #define BABEL_TIME_UNITS               100     /* On-wire times are counted in centiseconds */
        !            53: #define BABEL_SEQNO_REQUEST_EXPIRY     60
        !            54: #define BABEL_GARBAGE_INTERVAL         300
        !            55: 
        !            56: /* Max interval that will not overflow when carried as 16-bit centiseconds */
        !            57: #define BABEL_MAX_INTERVAL             (0xFFFF/BABEL_TIME_UNITS)
        !            58: 
        !            59: #define BABEL_OVERHEAD         (SIZE_OF_IP_HEADER+UDP_HEADER_LENGTH)
        !            60: #define BABEL_MIN_MTU          (512 + BABEL_OVERHEAD)
        !            61: 
        !            62: 
        !            63: enum babel_tlv_type {
        !            64:   BABEL_TLV_PAD1               = 0,
        !            65:   BABEL_TLV_PADN               = 1,
        !            66:   BABEL_TLV_ACK_REQ            = 2,
        !            67:   BABEL_TLV_ACK                        = 3,
        !            68:   BABEL_TLV_HELLO              = 4,
        !            69:   BABEL_TLV_IHU                = 5,
        !            70:   BABEL_TLV_ROUTER_ID          = 6,
        !            71:   BABEL_TLV_NEXT_HOP           = 7,
        !            72:   BABEL_TLV_UPDATE             = 8,
        !            73:   BABEL_TLV_ROUTE_REQUEST      = 9,
        !            74:   BABEL_TLV_SEQNO_REQUEST      = 10,
        !            75:   /* extensions - not implemented
        !            76:   BABEL_TLV_TS_PC              = 11,
        !            77:   BABEL_TLV_HMAC               = 12,
        !            78:   BABEL_TLV_SS_UPDATE          = 13,
        !            79:   BABEL_TLV_SS_REQUEST         = 14,
        !            80:   BABEL_TLV_SS_SEQNO_REQUEST   = 15,
        !            81:   */
        !            82:   BABEL_TLV_MAX
        !            83: };
        !            84: 
        !            85: enum babel_iface_type {
        !            86:   /* In practice, UNDEF and WIRED give equivalent behaviour */
        !            87:   BABEL_IFACE_TYPE_UNDEF       = 0,
        !            88:   BABEL_IFACE_TYPE_WIRED       = 1,
        !            89:   BABEL_IFACE_TYPE_WIRELESS    = 2,
        !            90:   BABEL_IFACE_TYPE_MAX
        !            91: };
        !            92: 
        !            93: enum babel_ae_type {
        !            94:   BABEL_AE_WILDCARD            = 0,
        !            95:   BABEL_AE_IP4                 = 1,
        !            96:   BABEL_AE_IP6                 = 2,
        !            97:   BABEL_AE_IP6_LL              = 3,
        !            98:   BABEL_AE_MAX
        !            99: };
        !           100: 
        !           101: 
        !           102: struct babel_config {
        !           103:   struct proto_config c;
        !           104: 
        !           105:   list iface_list;              /* Patterns configured -- keep it first; see babel_reconfigure why */
        !           106: };
        !           107: 
        !           108: struct babel_iface_config {
        !           109:   struct iface_patt i;
        !           110: 
        !           111:   u16 rxcost;
        !           112:   u8 type;
        !           113:   u8 check_link;
        !           114:   uint port;
        !           115:   u16 hello_interval;
        !           116:   u16 ihu_interval;
        !           117:   u16 update_interval;
        !           118: 
        !           119:   u16 rx_buffer;                       /* RX buffer size, 0 for MTU */
        !           120:   u16 tx_length;                       /* TX packet length limit (including headers), 0 for MTU */
        !           121:   int tx_tos;
        !           122:   int tx_priority;
        !           123: };
        !           124: 
        !           125: struct babel_proto {
        !           126:   struct proto p;
        !           127:   timer *timer;
        !           128:   struct fib rtable;
        !           129:   list interfaces;                     /* Interfaces we really know about (struct babel_iface) */
        !           130:   u64 router_id;
        !           131:   u16 update_seqno;                    /* To be increased on request */
        !           132:   u8 triggered;                                /* For triggering global updates */
        !           133: 
        !           134:   slab *route_slab;
        !           135:   slab *source_slab;
        !           136:   slab *msg_slab;
        !           137: 
        !           138:   slab *seqno_slab;
        !           139:   list seqno_cache;                    /* Seqno requests in the cache (struct babel_seqno_request) */
        !           140: 
        !           141:   struct tbf log_pkt_tbf;              /* TBF for packet messages */
        !           142: };
        !           143: 
        !           144: struct babel_iface {
        !           145:   node n;
        !           146: 
        !           147:   struct babel_proto *proto;
        !           148:   struct iface *iface;
        !           149: 
        !           150:   struct babel_iface_config *cf;
        !           151: 
        !           152:   u8 up;
        !           153: 
        !           154:   pool *pool;
        !           155:   char *ifname;
        !           156:   sock *sk;
        !           157:   ip_addr addr;
        !           158:   int tx_length;
        !           159:   list neigh_list;                     /* List of neighbors seen on this iface (struct babel_neighbor) */
        !           160:   list msg_queue;
        !           161: 
        !           162:   u16 hello_seqno;                     /* To be increased on each hello */
        !           163: 
        !           164:   bird_clock_t next_hello;
        !           165:   bird_clock_t next_regular;
        !           166:   bird_clock_t next_triggered;
        !           167:   bird_clock_t want_triggered;
        !           168: 
        !           169:   timer *timer;
        !           170:   event *send_event;
        !           171: };
        !           172: 
        !           173: struct babel_neighbor {
        !           174:   node n;
        !           175:   struct babel_iface *ifa;
        !           176: 
        !           177:   ip_addr addr;
        !           178:   u16 txcost;
        !           179:   u8 hello_cnt;
        !           180:   u16 hello_map;
        !           181:   u16 next_hello_seqno;
        !           182:   /* expiry timers */
        !           183:   bird_clock_t hello_expiry;
        !           184:   bird_clock_t ihu_expiry;
        !           185: 
        !           186:   list routes;                         /* Routes this neighbour has sent us (struct babel_route) */
        !           187: };
        !           188: 
        !           189: struct babel_source {
        !           190:   node n;
        !           191: 
        !           192:   u64 router_id;
        !           193:   u16 seqno;
        !           194:   u16 metric;
        !           195:   bird_clock_t expires;
        !           196: };
        !           197: 
        !           198: struct babel_route {
        !           199:   node n;
        !           200:   node neigh_route;
        !           201:   struct babel_entry    *e;
        !           202:   struct babel_neighbor *neigh;
        !           203: 
        !           204:   u16 seqno;
        !           205:   u16 advert_metric;
        !           206:   u16 metric;
        !           207:   u64 router_id;
        !           208:   ip_addr next_hop;
        !           209:   bird_clock_t refresh_time;
        !           210:   bird_clock_t expires;
        !           211:   u16 expiry_interval;
        !           212: };
        !           213: 
        !           214: struct babel_entry {
        !           215:   struct fib_node n;
        !           216:   struct babel_proto *proto;
        !           217:   struct babel_route *selected_in;
        !           218:   struct babel_route *selected_out;
        !           219: 
        !           220:   bird_clock_t updated;
        !           221: 
        !           222:   list sources;                                /* Source entries for this prefix (struct babel_source). */
        !           223:   list routes;                         /* Routes for this prefix (struct babel_route) */
        !           224: };
        !           225: 
        !           226: /* Stores forwarded seqno requests for duplicate suppression. */
        !           227: struct babel_seqno_request {
        !           228:   node n;
        !           229:   ip_addr prefix;
        !           230:   u8  plen;
        !           231:   u64 router_id;
        !           232:   u16 seqno;
        !           233:   bird_clock_t updated;
        !           234: };
        !           235: 
        !           236: 
        !           237: /*
        !           238:  *     Internal TLV messages
        !           239:  */
        !           240: 
        !           241: struct babel_msg_ack_req {
        !           242:   u8 type;
        !           243:   u16 nonce;
        !           244:   u16 interval;
        !           245:   ip_addr sender;
        !           246: };
        !           247: 
        !           248: struct babel_msg_ack {
        !           249:   u8 type;
        !           250:   u16 nonce;
        !           251: };
        !           252: 
        !           253: struct babel_msg_hello {
        !           254:   u8 type;
        !           255:   u16 seqno;
        !           256:   u16 interval;
        !           257:   ip_addr sender;
        !           258: };
        !           259: 
        !           260: struct babel_msg_ihu {
        !           261:   u8 type;
        !           262:   u8 ae;
        !           263:   u16 rxcost;
        !           264:   u16 interval;
        !           265:   ip_addr addr;
        !           266:   ip_addr sender;
        !           267: };
        !           268: 
        !           269: struct babel_msg_update {
        !           270:   u8 type;
        !           271:   u8 wildcard;
        !           272:   u8 plen;
        !           273:   u16 interval;
        !           274:   u16 seqno;
        !           275:   u16 metric;
        !           276:   ip_addr prefix;
        !           277:   u64 router_id;
        !           278:   ip_addr next_hop;
        !           279:   ip_addr sender;
        !           280: };
        !           281: 
        !           282: struct babel_msg_route_request {
        !           283:   u8 type;
        !           284:   u8 full;
        !           285:   u8 plen;
        !           286:   ip_addr prefix;
        !           287: };
        !           288: 
        !           289: struct babel_msg_seqno_request {
        !           290:   u8 type;
        !           291:   u8 plen;
        !           292:   u16 seqno;
        !           293:   u8 hop_count;
        !           294:   u64 router_id;
        !           295:   ip_addr prefix;
        !           296:   ip_addr sender;
        !           297: };
        !           298: 
        !           299: union babel_msg {
        !           300:   u8 type;
        !           301:   struct babel_msg_ack_req ack_req;
        !           302:   struct babel_msg_ack ack;
        !           303:   struct babel_msg_hello hello;
        !           304:   struct babel_msg_ihu ihu;
        !           305:   struct babel_msg_update update;
        !           306:   struct babel_msg_route_request route_request;
        !           307:   struct babel_msg_seqno_request seqno_request;
        !           308: };
        !           309: 
        !           310: struct babel_msg_node {
        !           311:   node n;
        !           312:   union babel_msg msg;
        !           313: };
        !           314: 
        !           315: 
        !           316: /* babel.c */
        !           317: void babel_handle_ack_req(union babel_msg *msg, struct babel_iface *ifa);
        !           318: void babel_handle_ack(union babel_msg *msg, struct babel_iface *ifa);
        !           319: void babel_handle_hello(union babel_msg *msg, struct babel_iface *ifa);
        !           320: void babel_handle_ihu(union babel_msg *msg, struct babel_iface *ifa);
        !           321: void babel_handle_router_id(union babel_msg *msg, struct babel_iface *ifa);
        !           322: void babel_handle_update(union babel_msg *msg, struct babel_iface *ifa);
        !           323: void babel_handle_route_request(union babel_msg *msg, struct babel_iface *ifa);
        !           324: void babel_handle_seqno_request(union babel_msg *msg, struct babel_iface *ifa);
        !           325: 
        !           326: void babel_show_interfaces(struct proto *P, char *iff);
        !           327: void babel_show_neighbors(struct proto *P, char *iff);
        !           328: void babel_show_entries(struct proto *P);
        !           329: 
        !           330: /* packets.c */
        !           331: void babel_enqueue(union babel_msg *msg, struct babel_iface *ifa);
        !           332: void babel_send_unicast(union babel_msg *msg, struct babel_iface *ifa, ip_addr dest);
        !           333: int babel_open_socket(struct babel_iface *ifa);
        !           334: void babel_send_queue(void *arg);
        !           335: 
        !           336: 
        !           337: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>