Annotation of embedaddon/bird/proto/rip/rip.h, revision 1.1
1.1 ! misho 1: /*
! 2: * BIRD -- Routing Information Protocol (RIP)
! 3: *
! 4: * (c) 1998--1999 Pavel Machek <pavel@ucw.cz>
! 5: * (c) 2004--2013 Ondrej Filip <feela@network.cz>
! 6: * (c) 2009--2015 Ondrej Zajicek <santiago@crfreenet.org>
! 7: * (c) 2009--2015 CZ.NIC z.s.p.o.
! 8: *
! 9: * Can be freely distributed and used under the terms of the GNU GPL.
! 10: */
! 11:
! 12: #ifndef _BIRD_RIP_H_
! 13: #define _BIRD_RIP_H_
! 14:
! 15: #include "nest/bird.h"
! 16: #include "nest/cli.h"
! 17: #include "nest/iface.h"
! 18: #include "nest/protocol.h"
! 19: #include "nest/route.h"
! 20: #include "nest/password.h"
! 21: #include "nest/locks.h"
! 22: #include "nest/bfd.h"
! 23: #include "lib/lists.h"
! 24: #include "lib/resource.h"
! 25: #include "lib/socket.h"
! 26: #include "lib/string.h"
! 27: #include "lib/timer.h"
! 28:
! 29:
! 30: #ifdef IPV6
! 31: #define RIP_IS_V2 0
! 32: #else
! 33: #define RIP_IS_V2 1
! 34: #endif
! 35:
! 36: #define RIP_V1 1
! 37: #define RIP_V2 2
! 38:
! 39: #define RIP_PORT 520 /* RIP for IPv4 */
! 40: #define RIP_NG_PORT 521 /* RIPng */
! 41:
! 42: #define RIP_MAX_PKT_LENGTH 532 /* 512 + IP4_HEADER_LENGTH */
! 43: #define RIP_AUTH_TAIL_LENGTH 4 /* Without auth_data */
! 44:
! 45: #define RIP_DEFAULT_ECMP_LIMIT 16
! 46: #define RIP_DEFAULT_INFINITY 16
! 47: #define RIP_DEFAULT_UPDATE_TIME 30
! 48: #define RIP_DEFAULT_TIMEOUT_TIME 180
! 49: #define RIP_DEFAULT_GARBAGE_TIME 120
! 50:
! 51:
! 52: struct rip_config
! 53: {
! 54: struct proto_config c;
! 55: list patt_list; /* List of iface configs (struct rip_iface_config) */
! 56:
! 57: u8 rip2; /* RIPv2 (IPv4) or RIPng (IPv6) */
! 58: u8 ecmp; /* Maximum number of nexthops in ECMP route, or 0 */
! 59: u8 infinity; /* Maximum metric value, representing infinity */
! 60:
! 61: u32 min_timeout_time; /* Minimum of interface timeout_time */
! 62: u32 max_garbage_time; /* Maximum of interface garbage_time */
! 63: };
! 64:
! 65: struct rip_iface_config
! 66: {
! 67: struct iface_patt i;
! 68: ip_addr address; /* Configured dst address */
! 69: u16 port; /* Src+dst port */
! 70: u8 metric; /* Incoming metric */
! 71: u8 mode; /* Interface mode (RIP_IM_*) */
! 72: u8 passive; /* Passive iface - no packets are sent */
! 73: u8 version; /* RIP version used for outgoing packets */
! 74: u8 version_only; /* FIXXX */
! 75: u8 split_horizon; /* Split horizon is used in route updates */
! 76: u8 poison_reverse; /* Poisoned reverse is used in route updates */
! 77: u8 check_zero; /* Validation of RIPv1 reserved fields */
! 78: u8 ecmp_weight; /* Weight for ECMP routes*/
! 79: u8 auth_type; /* Authentication type (RIP_AUTH_*) */
! 80: u8 ttl_security; /* bool + 2 for TX only (send, but do not check on RX) */
! 81: u8 check_link; /* Whether iface link change is used */
! 82: u8 bfd; /* Use BFD on iface */
! 83: u16 rx_buffer; /* RX buffer size, 0 for MTU */
! 84: u16 tx_length; /* TX packet length limit (including headers), 0 for MTU */
! 85: int tx_tos;
! 86: int tx_priority;
! 87: u32 update_time; /* Periodic update interval */
! 88: u32 timeout_time; /* Route expiration timeout */
! 89: u32 garbage_time; /* Unreachable entry GC timeout */
! 90: list *passwords; /* Passwords for authentication */
! 91: };
! 92:
! 93: struct rip_proto
! 94: {
! 95: struct proto p;
! 96: struct fib rtable; /* Internal routing table */
! 97: list iface_list; /* List of interfaces (struct rip_iface) */
! 98: slab *rte_slab; /* Slab for internal routes (struct rip_rte) */
! 99: timer *timer; /* Main protocol timer */
! 100:
! 101: u8 ecmp; /* Maximum number of nexthops in ECMP route, or 0 */
! 102: u8 infinity; /* Maximum metric value, representing infinity */
! 103: u8 triggered; /* Logical AND of interface want_triggered values */
! 104: u8 rt_reload; /* Route reload is scheduled */
! 105:
! 106: struct tbf log_pkt_tbf; /* TBF for packet messages */
! 107: struct tbf log_rte_tbf; /* TBF for RTE messages */
! 108: };
! 109:
! 110: struct rip_iface
! 111: {
! 112: node n;
! 113: struct rip_proto *rip;
! 114: struct iface *iface; /* Underyling core interface */
! 115: struct rip_iface_config *cf; /* Related config, must be updated in reconfigure */
! 116: struct object_lock *lock; /* Interface lock */
! 117: timer *timer; /* Interface timer */
! 118: sock *sk; /* UDP socket */
! 119:
! 120: u8 up; /* Interface is active */
! 121: u8 csn_ready; /* Nonzero CSN can be used */
! 122: u16 tx_plen; /* Max TX packet data length */
! 123: u32 csn; /* Last used crypto sequence number */
! 124: ip_addr addr; /* Destination multicast/broadcast address */
! 125: list neigh_list; /* List of iface neighbors (struct rip_neighbor) */
! 126:
! 127: /* Update scheduling */
! 128: bird_clock_t next_regular; /* Next time when regular update should be called */
! 129: bird_clock_t next_triggered; /* Next time when triggerd update may be called */
! 130: bird_clock_t want_triggered; /* Nonzero if triggered update is scheduled */
! 131:
! 132: /* Active update */
! 133: int tx_active; /* Update session is active */
! 134: ip_addr tx_addr; /* Update session destination address */
! 135: bird_clock_t tx_changed; /* Minimal changed time for triggered update */
! 136: struct fib_iterator tx_fit; /* FIB iterator in RIP routing table (p.rtable) */
! 137: };
! 138:
! 139: struct rip_neighbor
! 140: {
! 141: node n;
! 142: struct rip_iface *ifa; /* Associated interface, may be NULL if stale */
! 143: struct neighbor *nbr; /* Associaded core neighbor, may be NULL if stale */
! 144: struct bfd_request *bfd_req; /* BFD request, if BFD is used */
! 145: bird_clock_t last_seen; /* Time of last received and accepted message */
! 146: u32 uc; /* Use count, number of routes linking the neighbor */
! 147: u32 csn; /* Last received crypto sequence number */
! 148: };
! 149:
! 150: struct rip_entry
! 151: {
! 152: struct fib_node n;
! 153: struct rip_rte *routes; /* List of incoming routes */
! 154:
! 155: u8 valid; /* Entry validity state (RIP_ENTRY_*) */
! 156: u8 metric; /* Outgoing route metric */
! 157: u16 tag; /* Outgoing route tag */
! 158: struct iface *from; /* Outgoing route from, NULL if from proto */
! 159: struct iface *iface; /* Outgoing route iface (for next hop) */
! 160: ip_addr next_hop; /* Outgoing route next hop */
! 161:
! 162: bird_clock_t changed; /* Last time when the outgoing route metric changed */
! 163: };
! 164:
! 165: struct rip_rte
! 166: {
! 167: struct rip_rte *next;
! 168:
! 169: struct rip_neighbor *from; /* Advertising router */
! 170: ip_addr next_hop; /* Route next hop (iface is from->nbr->iface) */
! 171: u16 metric; /* Route metric (after increase) */
! 172: u16 tag; /* Route tag */
! 173:
! 174: bird_clock_t expires; /* Time of route expiration */
! 175: };
! 176:
! 177:
! 178: #define RIP_AUTH_NONE 0
! 179: #define RIP_AUTH_PLAIN 2
! 180: #define RIP_AUTH_CRYPTO 3
! 181:
! 182: #define RIP_IM_MULTICAST 1
! 183: #define RIP_IM_BROADCAST 2
! 184:
! 185: #define RIP_ENTRY_DUMMY 0 /* Only used to store list of incoming routes */
! 186: #define RIP_ENTRY_VALID 1 /* Valid outgoing route */
! 187: #define RIP_ENTRY_STALE 2 /* Stale outgoing route, waiting for GC */
! 188:
! 189: #define EA_RIP_METRIC EA_CODE(EAP_RIP, 0)
! 190: #define EA_RIP_TAG EA_CODE(EAP_RIP, 1)
! 191:
! 192: #define rip_is_v2(X) RIP_IS_V2
! 193: #define rip_is_ng(X) (!RIP_IS_V2)
! 194:
! 195: /*
! 196: static inline int rip_is_v2(struct rip_proto *p)
! 197: { return p->rip2; }
! 198:
! 199: static inline int rip_is_ng(struct rip_proto *p)
! 200: { return ! p->rip2; }
! 201: */
! 202:
! 203: static inline void
! 204: rip_reset_tx_session(struct rip_proto *p, struct rip_iface *ifa)
! 205: {
! 206: if (ifa->tx_active)
! 207: {
! 208: FIB_ITERATE_UNLINK(&ifa->tx_fit, &p->rtable);
! 209: ifa->tx_active = 0;
! 210: }
! 211: }
! 212:
! 213: /* rip.c */
! 214: void rip_update_rte(struct rip_proto *p, ip_addr *prefix, int pxlen, struct rip_rte *new);
! 215: void rip_withdraw_rte(struct rip_proto *p, ip_addr *prefix, int pxlen, struct rip_neighbor *from);
! 216: struct rip_neighbor * rip_get_neighbor(struct rip_proto *p, ip_addr *a, struct rip_iface *ifa);
! 217: void rip_update_bfd(struct rip_proto *p, struct rip_neighbor *n);
! 218: void rip_show_interfaces(struct proto *P, char *iff);
! 219: void rip_show_neighbors(struct proto *P, char *iff);
! 220:
! 221: /* packets.c */
! 222: void rip_send_request(struct rip_proto *p, struct rip_iface *ifa);
! 223: void rip_send_table(struct rip_proto *p, struct rip_iface *ifa, ip_addr addr, bird_clock_t changed);
! 224: int rip_open_socket(struct rip_iface *ifa);
! 225:
! 226:
! 227: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>