Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / lsack.c @ 9669362f

History | View | Annotate | Download (4.68 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
/* Note, that h is in network endianity! */
12
void
13
ospf_lsack_direct_tx(struct ospf_neighbor *n,struct ospf_lsa_header *h)
14
{
15
  struct ospf_packet *op;
16
  struct ospf_lsack_packet *pk;
17
  sock *sk=n->ifa->ip_sk;
18
  struct proto *p=&n->ifa->proto->proto;
19
  u16 len;
20

    
21
  DBG("Sending direct ACK to %I for Type: %u, ID: %I, RT: %I\n",n->rid,
22
    h->type, ntohl(h->id), ntohl(h->rt));
23

    
24
  pk=(struct ospf_lsack_packet *)sk->tbuf;
25
  op=(struct ospf_packet *)sk->tbuf;
26

    
27
  fill_ospf_pkt_hdr(n->ifa, pk, LSACK);
28

    
29
  memcpy(pk+1,h,sizeof(struct ospf_lsa_header));
30
  len=sizeof(struct ospf_lsack_packet)+sizeof(struct ospf_lsa_header);
31
  op->length=htons(len);
32
  ospf_pkt_finalize(n->ifa, op);
33
  sk_send_to(sk,len, n->ip, OSPF_PROTO);
34
  debug("%s: LS ack sent to %I\n", p->name, n->ip);
35
}
36

    
37
void
38
ospf_lsa_delay(struct ospf_neighbor *n,struct ospf_lsa_header *h,
39
  struct proto *p)
40
{
41
  struct lsah_n *no;
42

    
43
  no=mb_alloc(p->pool,sizeof(struct lsah_n));
44
  memcpy(&no->lsa,h,sizeof(struct ospf_lsa_header));
45
  add_tail(&n->ackl, NODE no);
46
  DBG("Adding delay ack for %I, ID: %I, RT: %I, Type: %u\n",n->rid,
47
    ntohl(h->id), ntohl(h->rt),h->type);
48
}
49

    
50
void
51
ackd_timer_hook(timer *t)
52
{
53
  struct ospf_neighbor *n=t->data;
54
  if(!EMPTY_LIST(n->ackl)) ospf_lsack_delay_tx(n);
55
}
56

    
57
void
58
ospf_lsack_delay_tx(struct ospf_neighbor *n)
59
{
60
  struct ospf_packet *op;
61
  struct ospf_lsack_packet *pk;
62
  sock *sk;
63
  u16 len,i=0;
64
  struct ospf_lsa_header *h;
65
  struct lsah_n *no;
66
  struct ospf_iface *ifa=n->ifa;
67

    
68
  DBG("Sending delay ack to %I\n", n->rid);
69

    
70
  if(ifa->type==OSPF_IT_BCAST)
71
  {
72
    sk=ifa->hello_sk;
73
  }
74
  else
75
  {
76
    sk=ifa->ip_sk;
77
  }
78

    
79
  pk=(struct ospf_lsack_packet *)sk->tbuf;
80
  op=(struct ospf_packet *)sk->tbuf;
81

    
82
  fill_ospf_pkt_hdr(n->ifa, pk, LSACK);
83
  h=(struct ospf_lsa_header *)(pk+1);
84

    
85
  while(!EMPTY_LIST(n->ackl))
86
  {
87
    no=(struct lsah_n *)HEAD(n->ackl);
88
    memcpy(h+i,&no->lsa, sizeof(struct ospf_lsa_header));
89
    i++;
90
    DBG("Iter %u ID: %I, RT: %I, Type: %u\n",i, ntohl((h+i)->id),
91
      ntohl((h+i)->rt),(h+i)->type);
92
    rem_node(NODE no);
93
    mb_free(no);
94
    if((i*sizeof(struct ospf_lsa_header)+sizeof(struct ospf_lsack_packet)+SIPH)>
95
      n->ifa->iface->mtu)
96
    {
97
      if(!EMPTY_LIST(n->ackl))
98
      {
99
        len=sizeof(struct ospf_lsack_packet)+i*sizeof(struct ospf_lsa_header);
100
        op->length=htons(len);
101
        ospf_pkt_finalize(n->ifa, op);
102
        DBG("Sending and continueing! Len=%u\n",len);
103
        if(ifa->type==OSPF_IT_BCAST)
104
        {
105
          if((ifa->state==OSPF_IS_DR)||(ifa->state==OSPF_IS_BACKUP))
106
          {
107
            sk_send_to(sk ,len, AllSPFRouters, OSPF_PROTO);
108
          }
109
          else
110
          {
111
            sk_send_to(sk ,len, AllDRouters, OSPF_PROTO);
112
          }
113
        }
114
        else
115
        {
116
          sk_send_to_agt(sk, len, ifa, NEIGHBOR_EXCHANGE);
117
        }
118

    
119
        fill_ospf_pkt_hdr(n->ifa, pk, LSACK);
120
        i=0;
121
      }
122
    }
123
  }
124

    
125
  len=sizeof(struct ospf_lsack_packet)+i*sizeof(struct ospf_lsa_header);
126
  op->length=htons(len);
127
  ospf_pkt_finalize(n->ifa, op);
128
  DBG("Sending! Len=%u\n",len);
129
  if(ifa->type==OSPF_IT_BCAST)
130
  {
131
    if((ifa->state==OSPF_IS_DR)||(ifa->state==OSPF_IS_BACKUP))
132
    {
133
      sk_send_to(sk ,len, AllSPFRouters, OSPF_PROTO);
134
    }
135
    else
136
    {
137
      sk_send_to(sk ,len, AllDRouters, OSPF_PROTO);
138
    }
139
  }
140
  else
141
  {
142
    sk_send_to_agt(sk, len, ifa, NEIGHBOR_EXCHANGE);
143
  }
144
}
145

    
146

    
147

    
148
void
149
ospf_lsack_rx(struct ospf_lsack_packet *ps, struct proto *p,
150
  struct ospf_iface *ifa, u16 size)
151
{
152
  u32 nrid, myrid;
153
  struct ospf_neighbor *n;
154
  struct ospf_lsa_header lsa,*plsa;
155
  int length;
156
  u16 nolsa,i;
157
  struct top_hash_entry *en;
158

    
159
  nrid=ntohl(ps->ospf_packet.routerid);
160

    
161
  myrid=p->cf->global->router_id;
162

    
163
  if((n=find_neigh(ifa, nrid))==NULL)
164
  {
165
    debug("%s: Received LS ack from unknown neigbor! (%I)\n", p->name,
166
      nrid);
167
    return ;
168
  }
169

    
170
  if(n->state<NEIGHBOR_EXCHANGE) return;
171

    
172
  debug("%s: Received LS ack from %I\n", p->name,
173
      n->ip);
174

    
175
  nolsa=(ntohs(ps->ospf_packet.length)-sizeof(struct ospf_lsack_packet))/
176
    sizeof(struct ospf_lsa_header);
177
  DBG("Received %d lsa ack(s)\n",nolsa);
178
  plsa=( struct ospf_lsa_header *)(ps+1);
179

    
180
  for(i=0;i<nolsa;i++)
181
  {
182
    ntohlsah(plsa+i,&lsa);
183
    if((en=ospf_hash_find_header(n->lsrth,&lsa))==NULL) continue;
184

    
185
    if(lsa_comp(&lsa,&en->lsa)!=CMP_SAME)
186
    {
187
      log("Strange LS acknoledgement from %I",n->rid);
188
      log("Id: %I, Rt: %I, Type: %u",lsa.id, lsa.rt, lsa.type);
189
      log("I have: Age: %u, Seqno: %u", en->lsa.age, en->lsa.sn);
190
      log("He has: Age: %u, Seqno: %u", lsa.age, lsa.sn);
191
      continue;
192
    }
193

    
194
    DBG("Deleting LS Id: %I RT: %I Type: %u from LS Retl for neighbor %I\n",
195
      lsa.id,lsa.rt,lsa.type,n->rid);
196
    s_rem_node(SNODE en);
197
    ospf_hash_delete(n->lsrth,en);
198
  }  
199
}