Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / lsreq.c @ 43e75f38

History | View | Annotate | Download (3.04 KB)

1
/*
2
 *        BIRD -- OSPF
3
 *
4
 *        (c) 2000 Ondrej Filip <feela@network.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#include "ospf.h"
10

    
11
void
12
ospf_lsreq_tx(struct ospf_neighbor *n)
13
{
14
  snode *sn;
15
  struct top_hash_entry *en;
16
  struct ospf_lsreq_packet *pk;
17
  struct ospf_packet *op;
18
  struct ospf_lsreq_header *lsh;
19
  u16 length;
20
  int i,j;
21

    
22
  pk=(struct ospf_lsreq_packet *)n->ifa->ip_sk->tbuf;
23
  op=(struct ospf_packet *)n->ifa->ip_sk->tbuf;
24

    
25
  fill_ospf_pkt_hdr(n->ifa, pk, LSREQ);
26

    
27
  sn=SHEAD(n->lsrql);
28
  if(EMPTY_SLIST(n->lsrql))
29
  {
30
    if(n->state==NEIGHBOR_LOADING) ospf_neigh_sm(n, INM_LOADDONE);
31
    return;
32
  }
33
 
34
  i=j=(n->ifa->iface->mtu-SIPH-sizeof(struct ospf_lsreq_packet))/
35
    sizeof(struct ospf_lsreq_header);
36
  lsh=(struct ospf_lsreq_header *)(pk+1);
37
  
38
  for(;i>0;i--)
39
  {
40
    en=(struct top_hash_entry *)sn;
41
    lsh->padd1=0; lsh->padd2=0;
42
    lsh->type=en->lsa.type;
43
    lsh->rt=htonl(en->lsa.rt);
44
    lsh->id=htonl(en->lsa.id);
45
    DBG("Requesting %uth LSA: Type: %u, Id: %I, RT: %I\n",i, en->lsa.type,
46
                    en->lsa.id, en->lsa.rt);
47
    lsh++;
48
    if(sn==STAIL(n->lsrql)) break;
49
    sn=sn->next;
50
  }
51
  if(i!=0) i--;
52

    
53
  length=sizeof(struct ospf_lsreq_packet)+(j-i)*sizeof(struct ospf_lsreq_header);
54
  op->length=htons(length);
55
  ospf_pkt_finalize(n->ifa, op);
56
  sk_send_to(n->ifa->ip_sk,length, n->ip, OSPF_PROTO);
57
  DBG("Lsreq send to: %I\n", n->rid);
58
}
59

    
60
void
61
lsrr_timer_hook(timer *timer)
62
{
63
  struct ospf_iface *ifa;
64
  struct proto *p;
65
  struct ospf_neighbor *n;
66

    
67
  n=(struct ospf_neighbor *)timer->data;
68
  ifa=n->ifa;
69
  p=(struct proto *)(ifa->proto);
70
  debug("%s: LSRR timer fired on interface %s for neigh: %I.\n",
71
    p->name, ifa->iface->name, n->rid);
72
  if(n->state<NEIGHBOR_FULL) ospf_lsreq_tx(n);
73
  else
74
  {
75
    int i;        /* FIXME Retransmit lsupd again */
76
  }
77
}
78

    
79
void
80
ospf_lsreq_rx(struct ospf_lsreq_packet *ps, struct proto *p,
81
  struct ospf_iface *ifa, u16 size)
82
{
83
  u32 nrid, myrid;
84
  struct ospf_neighbor *n;
85
  struct ospf_lsreq_header *lsh;
86
  struct l_lsr_head *llsh;
87
  list uplist;
88
  slab *upslab;
89
  int length;
90
  u8 i;
91

    
92
  nrid=ntohl(ps->ospf_packet.routerid);
93

    
94
  myrid=p->cf->global->router_id;
95

    
96
  if((n=find_neigh(ifa, nrid))==NULL)
97
  {
98
    debug("%s: Received lsreq from unknown neigbor! (%I)\n", p->name,
99
      nrid);
100
    return ;
101
  }
102
  if(n->state<NEIGHBOR_EXCHANGE) debug("%s: Ignoring it.\n", p->name);
103

    
104
  length=htons(ps->ospf_packet.length);
105
  lsh=(void *)(ps+1);
106
  init_list(&uplist);
107
  upslab=sl_new(p->pool,sizeof(struct l_lsr_head));
108

    
109
  for(i=0;i<(length-sizeof(struct ospf_lsreq_packet))/
110
    sizeof(struct ospf_lsreq_header);i++);
111
  {
112
    DBG("Processing LSA: ID=%I, Type=%u, Router=%I\n", ntohl(lsh->id),
113
    lsh->type, ntohl(lsh->rt));
114
    llsh=sl_alloc(upslab);
115
    llsh->lsh.id=ntohl(lsh->id);
116
    llsh->lsh.rt=ntohl(lsh->rt);
117
    llsh->lsh.type=lsh->type;
118
    add_tail(&uplist, NODE llsh);
119
    if(ospf_hash_find(n->ifa->oa->gr, llsh->lsh.id, llsh->lsh.rt,
120
      llsh->lsh.type)==NULL)
121
    {
122
      ospf_neigh_sm(n,INM_BADLSREQ);
123
      rfree(upslab);
124
      return;
125
    }
126
  }
127
  ospf_lsupd_tx_list(n, &uplist);
128
  rfree(upslab);
129
}
130