1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/*
* BIRD -- OSPF
*
* (c) 2000 Ondrej Filip <feela@network.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include "ospf.h"
/* Note, that h is in network endianity! */
void
ospf_lsack_direct_tx(struct ospf_neighbor *n,struct ospf_lsa_header *h)
{
struct ospf_packet *op;
struct ospf_lsack_packet *pk;
sock *sk=n->ifa->ip_sk;
u16 len;
DBG("Sending direct ACK to %I for Type: %u, ID: %I, RT: %I\n",n->rid,
h->type, ntohl(h->id), ntohl(h->rt));
pk=(struct ospf_lsack_packet *)sk->tbuf;
op=(struct ospf_packet *)sk->tbuf;
fill_ospf_pkt_hdr(n->ifa, pk, LSACK);
memcpy(pk+1,h,sizeof(struct ospf_lsa_header));
len=sizeof(struct ospf_lsack_packet)+sizeof(struct ospf_lsa_header);
op->length=htons(len);
ospf_pkt_finalize(n->ifa, op);
sk_send_to(sk,len, n->ip, OSPF_PROTO);
}
void
ospf_lsa_delay(struct ospf_neighbor *n,struct ospf_lsa_header *h,
struct proto *p)
{
struct lsah_n *no;
no=mb_alloc(p->pool,sizeof(struct lsah_n));
memcpy(&no->lsa,h,sizeof(struct ospf_lsa_header));
add_tail(&n->ackl, NODE no);
DBG("Adding delay ack for %I, ID: %I, RT: %I, Type: %u\n",n->rid,
ntohl(h->id), ntohl(h->rt),h->type);
}
void
ackd_timer_hook(timer *t)
{
struct ospf_neighbor *n=t->data;
if(!EMPTY_LIST(n->ackl)) ospf_lsack_delay_tx(n);
}
void
ospf_lsack_delay_tx(struct ospf_neighbor *n)
{
struct ospf_packet *op;
struct ospf_lsack_packet *pk;
sock *sk;
u16 len,i=0;
struct ospf_lsa_header *h;
struct lsah_n *no;
struct ospf_iface *ifa=n->ifa;
DBG("Sending delay ack to %I\n", n->rid);
if(ifa->type==OSPF_IT_BCAST)
{
sk=ifa->hello_sk;
}
else
{
sk=ifa->ip_sk;
}
pk=(struct ospf_lsack_packet *)sk->tbuf;
op=(struct ospf_packet *)sk->tbuf;
fill_ospf_pkt_hdr(n->ifa, pk, LSACK);
h=(struct ospf_lsa_header *)(pk+1);
while(!EMPTY_LIST(n->ackl))
{
no=(struct lsah_n *)HEAD(n->ackl);
memcpy(h+i,&no->lsa, sizeof(struct ospf_lsa_header));
i++;
DBG("Iter %u ID: %I, RT: %I, Type: %u\n",i, ntohl((h+i)->id),
ntohl((h+i)->rt),(h+i)->type);
rem_node(NODE no);
mb_free(no);
if((i*sizeof(struct ospf_lsa_header)+sizeof(struct ospf_lsack_packet)+SIPH)>
n->ifa->iface->mtu)
{
if(!EMPTY_LIST(n->ackl))
{
len=sizeof(struct ospf_lsack_packet)+i*sizeof(struct ospf_lsa_header);
op->length=htons(len);
ospf_pkt_finalize(n->ifa, op);
DBG("Sending and continueing! Len=%u\n",len);
/*
if(ifa->type==OSPF_IT_BCAST)
{
if((ifa->state==OSPF_IS_DR)||(ifa->state==OSPF_IS_BACKUP))
{
sk_send_to(sk ,len, AllSPFRouters, OSPF_PROTO);
}
else
{
sk_send_to(sk ,len, AllDRouters, OSPF_PROTO);
}
}
else
{
sk_send_to_agt(sk, len, ifa, NEIGHBOR_EXCHANGE);
}
*/
fill_ospf_pkt_hdr(n->ifa, pk, LSACK);
i=0;
}
}
}
len=sizeof(struct ospf_lsack_packet)+i*sizeof(struct ospf_lsa_header);
op->length=htons(len);
ospf_pkt_finalize(n->ifa, op);
DBG("Sending! Len=%u\n",len);
/*
if(ifa->type==OSPF_IT_BCAST)
{
if((ifa->state==OSPF_IS_DR)||(ifa->state==OSPF_IS_BACKUP))
{
sk_send_to(sk ,len, AllSPFRouters, OSPF_PROTO);
}
else
{
sk_send_to(sk ,len, AllDRouters, OSPF_PROTO);
}
}
else
{
sk_send_to_agt(sk, len, ifa, NEIGHBOR_EXCHANGE);
}
*/
}
void
ospf_lsack_rx(struct ospf_lsack_packet *ps, struct proto *p,
struct ospf_iface *ifa, u16 size)
{
u32 nrid, myrid;
struct ospf_neighbor *n;
struct ospf_lsa_header lsa,*plsa;
int length;
u16 nolsa,i;
struct top_hash_entry *en;
nrid=ntohl(ps->ospf_packet.routerid);
myrid=p->cf->global->router_id;
if((n=find_neigh(ifa, nrid))==NULL)
{
debug("%s: Received lsack from unknown neigbor! (%I)\n", p->name,
nrid);
return ;
}
if(n->state<NEIGHBOR_EXCHANGE) return;
nolsa=(ntohs(ps->ospf_packet.length)-sizeof(struct ospf_lsack_packet))/
sizeof(struct ospf_lsa_header);
DBG("Received %d lsa ack(s)\n",nolsa);
plsa=( struct ospf_lsa_header *)(ps+1);
for(i=0;i<nolsa;i++)
{
ntohlsah(plsa+i,&lsa);
if((en=ospf_hash_find_header(n->lsrth,&lsa))==NULL) continue;
if(lsa_comp(&lsa,&en->lsa)!=CMP_SAME)
{
log("Strange LS acknoledgement from %d\n",n->rid);
continue;
}
DBG("Deleting LS Id: %I RT: %I Type: %u from LS Retl for neighbor %I\n",
lsa.id,lsa.rt,lsa.type,n->rid);
s_rem_node(SNODE en);
ospf_hash_delete(n->lsrth,en);
}
}
|