Commit 6a8d3f1c authored by Ondřej Zajíček's avatar Ondřej Zajíček

BFD work in progress.

Now it compiles and mostly works.
parent bf139664
......@@ -73,6 +73,7 @@ CF_DECLS
%type <iface> ipa_scope
%type <i> expr bool pxlen
%type <i32> expr_us
%type <time> datetime
%type <a> ipa
%type <px> prefix prefix_or_ipa
......@@ -86,7 +87,7 @@ CF_DECLS
%left '!'
%nonassoc '.'
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO)
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, XS, XMS, XUS)
CF_GRAMMAR
......@@ -124,6 +125,14 @@ expr:
$$ = SYM_VAL($1).i; }
;
/* XXX fix X* symbols, they collide with macros */
expr_us:
expr XS { $$ = (u32) $1 * 1000000; }
| expr XMS { $$ = (u32) $1 * 1000; }
| expr XUS { $$ = (u32) $1 * 1; }
;
/* expr_u16: expr { check_u16($1); $$ = $1; }; */
/* Switches */
......
......@@ -47,11 +47,11 @@ AC_SUBST(runtimedir)
if test "$enable_ipv6" = yes ; then
ip=ipv6
SUFFIX=6
all_protocols=bgp,ospf,pipe,radv,rip,static
all_protocols=bfd,bgp,ospf,pipe,radv,rip,static
else
ip=ipv4
SUFFIX=""
all_protocols=bgp,ospf,pipe,rip,static
all_protocols=bfd,bgp,ospf,pipe,rip,static
fi
if test "$given_suffix" = yes ; then
......@@ -92,7 +92,7 @@ if test "$bird_cflags_default" = yes ; then
BIRD_CHECK_GCC_OPTION(bird_cv_c_option_fno_strict_aliasing, -fno-strict-aliasing)
BIRD_CHECK_GCC_OPTION(bird_cv_c_option_fno_strict_overflow, -fno-strict-overflow)
CFLAGS="$CFLAGS -Wall -Wstrict-prototypes -Wno-parentheses"
CFLAGS="$CFLAGS -pthread -Wall -Wstrict-prototypes -Wno-parentheses"
BIRD_ADD_GCC_OPTION(bird_cv_c_option_wno_pointer_sign, -Wno-pointer-sign)
BIRD_ADD_GCC_OPTION(bird_cv_c_option_fno_strict_aliasing, -fno-strict-aliasing)
BIRD_ADD_GCC_OPTION(bird_cv_c_option_fno_strict_overflow, -fno-strict-overflow)
......
#define HASH(type) struct { type **data; uint used, size; }
#define HASH(type) struct { type **data; uint count, order; }
#define HASH_TYPE(v) typeof(** (v).data)
#define HASH_SIZE(v) ((v).size * sizeof(* (v).data))
#define HASH_SIZE(v) (1 << (v).order)
#define HASH_MASK(v) ((1 << (v).order)-1)
#define HASH_INIT(v,pool,isize) \
#define HASH_INIT(v,pool,init_order) \
({ \
(v).used = 0; \
(v).size = (isize); \
(v).data = mb_allocz(pool, HASH_SIZE(v)); \
(v).count = 0; \
(v).order = (init_order); \
(v).data = mb_allocz(pool, HASH_SIZE(v) * sizeof(* (v).data)); \
})
#define HASH_FIND(v,id,key) \
#define HASH_FIND(v,id,key...) \
({ \
HASH_TYPE(v) *_n = (v).data[id##_FN(key, (v).size)]; \
while (_n && !id##_EQ(_n, key)) \
_n = _n->id##_NEXT; \
uint _h = id##_FN((key)) & HASH_MASK(v); \
HASH_TYPE(v) *_n = (v).data[_h]; \
while (_n && !id##_EQ(id##_KEY(_n), (key))) \
_n = id##_NEXT(_n); \
_n; \
})
#define HASH_INSERT(v,id,key,node) \
#define HASH_INSERT(v,id,node) \
({ \
HASH_TYPE(v) **_nn = (v).data + id##_FN(key, (v).size); \
node->id##_NEXT = *_nn; \
uint _h = id##_FN(id##_KEY((node))) & HASH_MASK(v); \
HASH_TYPE(v) **_nn = (v).data + _h; \
id##_NEXT(node) = *_nn; \
*_nn = node; \
(v).count++; \
})
#define HASH_DELETE(v,id,key) \
#define HASH_DO_REMOVE(v,id,_nn) \
({ \
HASH_TYPE(v) **_nn = (v).data + id##_FN(key, (v).size); \
while ((*_nn) && !id##_EQ(*_nn, key)) \
_nn = &((*_nn)->id##_NEXT); \
\
HASH_TYPE(v) *_n = *_nn; \
if (_n) \
*_nn = _n->id##_NEXT; \
{ \
*_nn = id##_NEXT(_n); \
(v).count--; \
} \
_n; \
})
#define HASH_DELETE(v,id,key...) \
({ \
uint _h = id##_FN((key)) & HASH_MASK(v); \
HASH_TYPE(v) **_nn = (v).data + _h; \
\
while ((*_nn) && !id##_EQ(id##_KEY((*_nn)), (key))) \
_nn = &(id##_NEXT((*_nn))); \
\
HASH_DO_REMOVE(v,id,_nn); \
})
#define HASH_REMOVE(v,id,node) \
({ \
HASH_TYPE(v) **_nn = (v).data + id##_FN(key, (v).size); \
uint _h = id##_FN(id##_KEY((node))) & HASH_MASK(v); \
HASH_TYPE(v) **_nn = (v).data + _h; \
\
while ((*_nn) && (*_nn != (node))) \
_nn = &((*_nn)->id##_NEXT); \
_nn = &(id##_NEXT((*_nn))); \
\
HASH_TYPE(v) *_n = *_nn; \
if (_n) \
*_nn = _n->id##_NEXT; \
_n; \
HASH_DO_REMOVE(v,id,_nn); \
})
#define HASH_REHASH(v,id,pool,step) \
({ \
HASH_TYPE(v) *_n, *_n2, **_od; \
uint _i, _s; \
\
_s = HASH_SIZE(v); \
_od = (v).data; \
(v).count = 0; \
(v).order += (step); \
(v).data = mb_allocz(pool, HASH_SIZE(v) * sizeof(* (v).data)); \
\
for (_i = 0; _i < _s; _i++) \
for (_n = _od[_i]; _n && (_n2 = id##_NEXT(_n), 1); _n = _n2) \
HASH_INSERT(v, id, _n); \
\
mb_free(_od); \
})
#define HASH_DEFINE_REHASH_FN(id, type) \
static void id##_REHASH_FN(void *v, pool *p, int step) \
{ HASH_REHASH(* (HASH(type) *) v, id, p, step); }
#define HASH_TRY_REHASH_UP(v,id,pool) \
({ \
if (((v).order < id##_REHASH_MAX) && ((v).count > HASH_SIZE(v))) \
id##_REHASH_FN(&v, pool, 1); \
})
#define HASH_TRY_REHASH_DOWN(v,id,pool) \
({ \
if (((v).order > id##_REHASH_MIN) && ((v).count < HASH_SIZE(v)/2)) \
id##_REHASH_FN(&v, pool, -1); \
})
#define HASH_WALK(v,next,n) \
do { \
HASH_TYPE(v) *n; \
uint _i; \
for (_i = 0; _i < ((v).size); _i++) \
uint _s = HASH_SIZE(v); \
for (_i = 0; _i < _s; _i++) \
for (n = (v).data[_i]; n; n = n->next)
#define HASH_WALK_END } while (0)
......@@ -66,18 +114,10 @@
do { \
HASH_TYPE(v) *n, *_next; \
uint _i; \
for (_i = 0; _i < ((v).size); _i++) \
uint _s = HASH_SIZE(v); \
for (_i = 0; _i < _s; _i++) \
for (n = (v).data[_i]; n && (_next = n->next, 1); n = _next)
#define HASH_WALK_DELSAFE_END } while (0)
/*
define HASH_REHASH(s) \
({ \
type *_n; \
uint _i; \
for (_i = 0; _i < (size_f); _i++) \
for (_n = (hash)[_i]; _n != NULL; _n =
*/
......@@ -72,8 +72,8 @@
**/
#define HEAP_INIT(heap,num,type,less,swap) \
do { \
uns _i = num; \
uns _j, _l; \
uint _i = num; \
uint _j, _l; \
type x; \
while (_i >= 1) \
{ \
......@@ -89,7 +89,7 @@
**/
#define HEAP_DELMIN(heap,num,type,less,swap) \
do { \
uns _j, _l; \
uint _j, _l; \
type x; \
swap(heap,1,num,x); \
num--; \
......@@ -102,7 +102,7 @@
**/
#define HEAP_INSERT(heap,num,type,less,swap) \
do { \
uns _j, _u; \
uint _j, _u; \
type x; \
_j = num; \
HEAP_BUBBLE_UP_J(heap,num,less,swap); \
......@@ -115,7 +115,7 @@
**/
#define HEAP_INCREASE(heap,num,type,less,swap,pos) \
do { \
uns _j, _l; \
uint _j, _l; \
type x; \
_j = pos; \
HEAP_BUBBLE_DOWN_J(heap,num,less,swap); \
......@@ -128,7 +128,7 @@
**/
#define HEAP_DECREASE(heap,num,type,less,swap,pos) \
do { \
uns _j, _u; \
uint _j, _u; \
type x; \
_j = pos; \
HEAP_BUBBLE_UP_J(heap,num,less,swap); \
......@@ -139,7 +139,7 @@
**/
#define HEAP_DELETE(heap,num,type,less,swap,pos) \
do { \
uns _j, _l, _u; \
uint _j, _l, _u; \
type x; \
_j = pos; \
swap(heap,_j,num,x); \
......
......@@ -100,6 +100,25 @@ rem_node(node *n)
x->prev = z;
}
/**
* rem2_node - remove a node from a list, with cleanup
* @n: node to be removed
*
* Removes a node @n from the list it's linked in and resets its pointers to NULL.
* Useful if you want to distinguish between linked and unlinked nodes.
*/
LIST_INLINE void
rem2_node(node *n)
{
node *z = n->prev;
node *x = n->next;
z->next = x;
x->prev = z;
n->next = NULL;
n->prev = NULL;
}
/**
* replace_node - replace a node in a list with another one
* @old: node to be removed
......
......@@ -51,6 +51,7 @@ typedef struct list { /* In fact two overlayed nodes */
void add_tail(list *, node *);
void add_head(list *, node *);
void rem_node(node *);
void rem2_node(node *);
void add_tail_list(list *, list *);
void init_list(list *);
void insert_node(node *, node *);
......
......@@ -220,7 +220,8 @@ ralloc(pool *p, struct resclass *c)
bzero(r, c->size);
r->class = c;
add_tail(&p->inside, &r->n);
if (p)
add_tail(&p->inside, &r->n);
return r;
}
......@@ -423,6 +424,6 @@ buffer_realloc(void **buf, unsigned *size, unsigned need, unsigned item_size)
while (nsize < need)
nsize = STEP_UP(nsize);
*buf = mb_realloc(*buf, nsize*isize);
*buf = mb_realloc(*buf, nsize * item_size);
*size = nsize;
}
......@@ -52,7 +52,7 @@ extern pool root_pool;
void *mb_alloc(pool *, unsigned size);
void *mb_allocz(pool *, unsigned size);
void *mb_realloc(pool *p, void *m, unsigned size);
void *mb_realloc(void *m, unsigned size);
void mb_free(void *);
/* Memory pools with linear allocation */
......@@ -78,6 +78,9 @@ void sl_free(slab *, void *);
* outside resource manager and possibly sysdep code.
*/
void buffer_realloc(void **buf, unsigned *size, unsigned need, unsigned item_size);
#ifdef HAVE_LIBDMALLOC
/*
* The standard dmalloc macros tend to produce lots of namespace
......@@ -103,3 +106,4 @@ void *xrealloc(void *, unsigned);
#endif
#endif
......@@ -718,6 +718,9 @@ protos_build(void)
#ifdef CONFIG_BGP
proto_build(&proto_bgp);
#endif
// XXX
proto_build(&proto_bfd);
proto_pool = rp_new(&root_pool, "Protocols");
proto_flush_event = ev_new(proto_pool);
proto_flush_event->hook = proto_flush_loop;
......
......@@ -75,7 +75,7 @@ void protos_dump_all(void);
extern struct protocol
proto_device, proto_radv, proto_rip, proto_static,
proto_ospf, proto_pipe, proto_bgp;
proto_ospf, proto_pipe, proto_bgp, proto_bfd;
/*
* Routing Protocol Instance
......@@ -358,6 +358,12 @@ void proto_notify_state(struct proto *p, unsigned state);
#define D_EVENTS 16 /* Protocol events */
#define D_PACKETS 32 /* Packets sent/received */
#ifndef PARSER
#define TRACE(flags, msg, args...) \
do { if (p->p.debug & flags) log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0)
#endif
/*
* MRTDump flags
*/
......
source=bfd.c
source=bfd.c packets.c io.c
root-rel=../../
dir-name=proto/bfd
......
This diff is collapsed.
/*
* BIRD -- Bidirectional Forwarding Detection (BFD)
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_BFD_H_
#define _BIRD_BFD_H_
#include <pthread.h>
#include "nest/bird.h"
#include "nest/cli.h"
#include "nest/iface.h"
#include "nest/protocol.h"
#include "nest/route.h"
#include "conf/conf.h"
#include "lib/hash.h"
#include "lib/resource.h"
#include "lib/socket.h"
#include "lib/string.h"
#include "io.h"
#define BFD_CONTROL_PORT 3784
#define BFD_ECHO_PORT 3785
#define BFD_MULTI_CTL_PORT 4784
......@@ -15,7 +36,7 @@
struct bfd_config
{
struct proto_config c;
list neighbors; /* List of struct bfd_neighbor */
list neigh_list; /* List of struct bfd_neighbor */
};
struct bfd_session_config
......@@ -42,12 +63,21 @@ struct bfd_neighbor
struct bfd_proto
{
struct proto p;
struct birdloop *loop;
pool *tpool;
pthread_spinlock_t lock;
slab *session_slab;
HASH(struct bfd_session) session_hash_id;
HASH(struct bfd_session) session_hash_ip;
list sockets;
sock *notify_rs;
sock *notify_ws;
list notify_list;
sock *rx_1;
sock *rx_m;
list sock_list;
};
struct bfd_socket
......@@ -60,16 +90,20 @@ struct bfd_socket
struct bfd_session
{
node n;
ip_addr addr; /* Address of session */
struct bfd_session *next_id; /* Next in bfd.session_hash_id */
struct bfd_session *next_ip; /* Next in bfd.session_hash_ip */
struct bfd_proto *bfd;
u8 opened;
u8 passive;
u8 poll_active;
u8 poll_scheduled;
u8 loc_state;
u8 rem_state;
u8 loc_diag;
u8 rem_diag;
u32 loc_id; /* Local session ID (local discriminator) */
u32 rem_id; /* Remote session ID (remote discriminator) */
u32 des_min_tx_int; /* Desired min rx interval, local option */
......@@ -83,11 +117,13 @@ struct bfd_session
u8 detect_mult; /* Announced detect_mult, local option */
u8 rem_detect_mult; /* Last received detect_mult */
xxx_time last_tx; /* Time of last sent periodic control packet */
xxx_time last_rx; /* Time of last received valid control packet */
btime last_tx; /* Time of last sent periodic control packet */
btime last_rx; /* Time of last received valid control packet */
timer2 *tx_timer; /* Periodic control packet timer */
timer2 *hold_timer; /* Timer for session down detection time */
struct bfd_socket *bsock; /* Socket associated with session */
};
......@@ -110,9 +146,30 @@ struct bfd_session
#define BFD_POLL_TX 1
#define BFD_POLL_RX 2
#define BFD_FLAG_POLL (1 << 5)
#define BFD_FLAG_FINAL (1 << 4)
#define BFD_FLAG_CPI (1 << 3)
#define BFD_FLAG_AP (1 << 2)
#define BFD_FLAG_DEMAND (1 << 1)
#define BFD_FLAG_MULTIPOINT (1 << 0)
static inline void bfd_lock_sessions(struct bfd_proto *p) { pthread_spin_lock(&p->lock); }
static inline void bfd_unlock_sessions(struct bfd_proto *p) { pthread_spin_unlock(&p->lock); }
/* bfd.c */
struct bfd_session * bfd_find_session_by_id(struct bfd_proto *p, u32 id);
struct bfd_session * bfd_find_session_by_addr(struct bfd_proto *p, ip_addr addr);
void bfd_session_process_ctl(struct bfd_session *s, u8 flags, u32 old_tx_int, u32 old_rx_int);
void bfd_show_sessions(struct proto *P);
/* packets.c */
void bfd_send_ctl(struct bfd_proto *p, struct bfd_session *s, int final);
sock * bfd_open_rx_sk(struct bfd_proto *p, int multihop);
struct bfd_socket * bfd_get_socket(struct bfd_proto *p, ip_addr local, struct iface *ifa);
void bfd_free_socket(struct bfd_socket *sk);
#endif _BIRD_BFD_H_
#endif /* _BIRD_BFD_H_ */
......@@ -22,7 +22,7 @@ static struct bfd_neighbor *this_bfd_neighbor;
CF_DECLS
CF_KEYWORDS(BFD, MIN, IDLE, RX, TX, INTERVAL, MULTIPLIER, MULTIHOP, PASSIVE,
NEIGHBOR)
NEIGHBOR, DEV)
%type <iface> bfd_neigh_iface
%type <a> bfd_neigh_local
......@@ -34,7 +34,7 @@ CF_ADDTO(proto, bfd_proto)
bfd_proto_start: proto_start BFD
{
this_proto = proto_config_new(&proto_bfd, sizeof(struct bfd_config), $1);
init_list(&BFD_CFG->neighbors);
init_list(&BFD_CFG->neigh_list);
};
bfd_proto_item:
......@@ -99,7 +99,7 @@ bfd_neigh_local:
bfd_neighbor: NEIGHBOR ipa bfd_neigh_iface bfd_neigh_local bfd_session
{
this_bfd_neighbor = cfg_allocz(sizeof(struct bfd_neighbor));
add_tail(&BFD_CFG->neighbors, NODE this_bfd_neighbor);
add_tail(&BFD_CFG->neigh_list, NODE this_bfd_neighbor);
BFD_NEIGHBOR->addr = $2;
BFD_NEIGHBOR->local = $4;
......@@ -108,6 +108,9 @@ bfd_neighbor: NEIGHBOR ipa bfd_neigh_iface bfd_neigh_local bfd_session
};
CF_CLI(SHOW BFD SESSIONS, optsym, [<name>], [[Show information about BFD sessions]])
{ bfd_show_sessions(proto_get_named($4, &proto_bfd)); };
CF_CODE
CF_END
This diff is collapsed.
/*
* BIRD -- I/O and event loop
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
typedef s64 xxx_time;
#ifndef _BIRD_BFD_IO_H_
#define _BIRD_BFD_IO_H_
typedef struct timer
#include "nest/bird.h"
#include "lib/lists.h"
#include "lib/resource.h"
#include "lib/event.h"
#include "lib/socket.h"
// #include "lib/timer.h"
#define S *1000000
#define MS *1000
#define US *1
#define TO_S /1000000
#define TO_MS /1000
#define TO_US /1
typedef s64 btime;
typedef struct timer2
{
resource r;
void (*hook)(struct timer2 *);
void *data;
xxx_time expires; /* 0=inactive */
unsigned randomize; /* Amount of randomization */
unsigned recurrent; /* Timer recurrence */
btime expires; /* 0=inactive */
uint randomize; /* Amount of randomization */
uint recurrent; /* Timer recurrence */
int index;
} timer;
} timer2;
btime current_time(void);
void ev2_schedule(event *e);
timer2 *tm2_new(pool *p);
void tm2_start(timer2 *t, xxx_time after);
void tm2_set(timer2 *t, btime when);
void tm2_start(timer2 *t, btime after);
void tm2_stop(timer2 *t);
static inline xxx_time
tm2_remains(timer2 *t)
static inline int
tm2_active(timer2 *t)
{
return (t->expires > xxxnow) ? t->expires - xxxnow : 0;
return t->expires != 0;
}
static inline void
tm2_start_max(timer2 *t, xxx_time after)
static inline btime
tm2_remains(timer2 *t)
{
xxx_time rem = tm2_remains(t);
tm2_start(t, MAX(rem, after));
btime now = current_time();
return (t->expires > now) ? (t->expires - now) : 0;
}
static inline timer2 *
tm2_new_set(pool *p, void (*hook)(struct timer2 *), void *data, uint rec, uint rand)
tm2_new_init(pool *p, void (*hook)(struct timer2 *), void *data, uint rec, uint rand)
{
timer2 *t = tm2_new(p);
t->hook = hook;
......@@ -48,6 +73,14 @@ tm2_new_set(pool *p, void (*hook)(struct timer2 *), void *data, uint rec, uint r
return t;
}
/*
static inline void
tm2_start_max(timer2 *t, btime after)
{
btime rem = tm2_remains(t);
tm2_start(t, _MAX(rem, after));
}
*/
void sk_start(sock *s);
......@@ -58,5 +91,8 @@ void sk_stop(sock *s);
struct birdloop *birdloop_new(pool *p);
void birdloop_enter(struct birdloop *loop);
void birdloop_leave(struct birdloop *loop);
void birdloop_main(struct birdloop *loop);
void birdloop_mask_wakeups(struct birdloop *loop);
void birdloop_unmask_wakeups(struct birdloop *loop);
#endif /* _BIRD_BFD_IO_H_ */
/*
* BIRD -- Bidirectional Forwarding Detection (BFD)
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#define BFD_FLAG_POLL (1 << 5)
#define BFD_FLAG_FINAL (1 << 4)
#define BFD_FLAG_CPI (1 << 3)
#define BFD_FLAG_AP (1 << 2)
#define BFD_FLAG_DEMAND (1 << 1)
#define BFD_FLAG_MULTIPOINT (1 << 0)
#include "bfd.h"
struct bfd_ctl_packet
......@@ -21,12 +20,14 @@ struct bfd_ctl_packet
u32 req_min_echo_rx_int;
};
#define BFD_BASE_LEN sizeof(struct bfd_ctl_packet)
static inline void bfd_pack_vdiag(u8 version, u8 diag)
static inline u8 bfd_pack_vdiag(u8 version, u8 diag)
{ return (version << 5) | diag; }
static inline void bfd_pack_flags(u8 state, u8 flags)
{ return (state << 6) | diag; }
static inline u8 bfd_pack_flags(u8 state, u8 flags)
{ return (state << 6) | flags; }
static inline u8 bfd_pkt_get_version(struct bfd_ctl_packet *pkt)
{ return pkt->vdiag >> 5; }
......@@ -45,17 +46,17 @@ static inline void bfd_pkt_set_state(struct bfd_ctl_packet *pkt, u8 val)
void
bfd_send_ctl(struct bfd_proto *p, struct bfd_session *s, int final)
{
sock *sk = p->skX;
struct bfd_ctl_packet *pkt = (struct ospf_packet *) sk->tbuf;
sock *sk = s->bsock->sk;
struct bfd_ctl_packet *pkt = (struct bfd_ctl_packet *) sk->tbuf;
pkt->vdiag = bfd_pack_vdiag(1, s->loc_diag);
pkt->flags = bfd_pack_flags(s->loc_state, 0);
pkt->detect_mult = s->detect_mult;
pkt->length = 24;
pkt->length = BFD_BASE_LEN;
pkt->snd_id = htonl(s->loc_id);
pkt->rcv_id = htonl(s->rem_id);
pkt->des_min_tx_int = htonl(s->des_min_tx_int);
pkt->req_min_rx_int = htonl(s->req_min_rx_int);
pkt->des_min_tx_int = htonl(s->des_min_tx_new);
pkt->req_min_rx_int = htonl(s->req_min_rx_new);
pkt->req_min_echo_rx_int = 0;
if (final)
......@@ -63,15 +64,21 @@ bfd_send_ctl(struct bfd_proto *p, struct bfd_session *s, int final)
else if (s->poll_active)
pkt->flags |= BFD_FLAG_POLL;
// XXX
sk_send_to(sk, len, dst, 0);
if (sk->tbuf != sk->tpos)
log(L_ERR "%s: old packet was overwritten in TX buffer", p->p.name);
sk_send_to(sk, pkt->length, s->addr, sk->dport);
}
int
bfd_ctl_rx_hook(sock *sk, int len)
#define DROP(DSC,VAL) do { err_dsc = DSC; err_val = VAL; goto drop; } while(0)
static int
bfd_rx_hook(sock *sk, int len)
{
struct bfd_proto *p = sk->data;
struct bfd_ctl_packet *pkt =sk->rbuf;
struct bfd_proto *p = sk->data;
struct bfd_ctl_packet *pkt = (struct bfd_ctl_packet *) sk->rbuf;
const char *err_dsc = NULL;
uint err_val = 0;
if (len < BFD_BASE_LEN)
DROP("too short", len);
......@@ -108,11 +115,11 @@ bfd_ctl_rx_hook(sock *sk, int len)
if (ps > BFD_STATE_DOWN)
DROP("invalid init state", ps);
s = bfd_find_session_by_ip(p, sk->faddr);
s = bfd_find_session_by_addr(p, sk->faddr);
/* FIXME: better session matching and message */
if (!s || !s->opened)
return;
return 1;
}
/* FIXME: better authentication handling and message */
......@@ -120,17 +127,18 @@ bfd_ctl_rx_hook(sock *sk, int len)
DROP("authentication not supported", 0);
u32 old_rx_int = s->des_min_tx_int;
u32 old_tx_int = s->rem_min_rx_int;
u32 old_tx_int = s->des_min_tx_int;
u32 old_rx_int = s->rem_min_rx_int;
s->rem_id = ntohl(pkt->snd_id);
s->rem_state = bfd_pkt_get_state(pkt);