Revision 061ab802 proto/ospf/lsalib.c

View differences:

proto/ospf/lsalib.c
99 99
#ifdef OSPFv2
100 100
  n->options = h->options;
101 101
#endif
102
  n->type = h->type;
102
  n->type = htont(h->type);
103 103
  n->id = htonl(h->id);
104 104
  n->rt = htonl(h->rt);
105 105
  n->sn = htonl(h->sn);
......
114 114
#ifdef OSPFv2
115 115
  h->options = n->options;
116 116
#endif
117
  h->type = n->type;
117
  h->type = ntoht(n->type);
118 118
  h->id = ntohl(n->id);
119 119
  h->rt = ntohl(n->rt);
120 120
  h->sn = ntohl(n->sn);
......
143 143
      nrt->links = htons(hrt->links);
144 144
      links = hrt->links;
145 145
#else /* OSPFv3 */
146
      hrt->options = htonl(nrt->options);
146
      nrt->options = htonl(hrt->options);
147 147
      links = (len - sizeof(struct ospf_lsa_rt)) /
148 148
	sizeof(struct ospf_lsa_rt_link);
149 149
#endif
......
173 173
  case LSA_T_SUM_NET:
174 174
  case LSA_T_SUM_RT:
175 175
  case LSA_T_EXT:
176
#ifdef OSPFv3
177
  case LSA_T_LINK:
178
  case LSA_T_PREFIX:
179
#endif
176 180
    {
177 181
      u32 *hid, *nid;
178 182

  
......
241 245
  case LSA_T_SUM_NET:
242 246
  case LSA_T_SUM_RT:
243 247
  case LSA_T_EXT:
248
#ifdef OSPFv3
249
  case LSA_T_LINK:
250
  case LSA_T_PREFIX:
251
#endif
244 252
    {
245 253
      u32 *hid, *nid;
246 254

  
......
258 266
  }
259 267
};
260 268

  
269
void
270
buf_dump(const char *hdr, const byte *buf, int blen)
271
{
272
  char b2[1024];
273
  char *bp;
274
  int first = 1;
275
  int i;
276

  
277
  const char *lhdr = hdr;
278

  
279
  bp = b2;
280
  for(i = 0; i < blen; i++)
281
    {
282
      if ((i > 0) && ((i % 16) == 0))
283
	{
284
	      *bp = 0;
285
	      log(L_WARN "%s\t%s", lhdr, b2);
286
	      lhdr = "";
287
	      bp = b2;
288
	}
289

  
290
      bp += snprintf(bp, 1022, "%02x ", buf[i]);
291

  
292
    }
293

  
294
  *bp = 0;
295
  log(L_WARN "%s\t%s", lhdr, b2);
296
}
297

  
261 298
#define MODX 4102		/* larges signed value without overflow */
262 299

  
263 300
/* Fletcher Checksum -- Refer to RFC1008. */
......
268 305
void
269 306
lsasum_calculate(struct ospf_lsa_header *h, void *body)
270 307
{
271
  u16 length;
272

  
273
  length = h->length;
308
  u16 length = h->length;
309
  u16 type = h->type;
274 310

  
311
  log(L_WARN "Checksum %R %R %d start (len %d)", h->id, h->rt, h->type, length);
275 312
  htonlsah(h, h);
276
  htonlsab(body, body, h->type, length - sizeof(struct ospf_lsa_header));
313

  
314
  htonlsab(body, body, type, length - sizeof(struct ospf_lsa_header));
315

  
316
  char buf[1024];
317
  memcpy(buf, h, sizeof(struct ospf_lsa_header));
318
  memcpy(buf + sizeof(struct ospf_lsa_header), body, length - sizeof(struct ospf_lsa_header));
319
  buf_dump("CALC", buf, length);
277 320

  
278 321
  (void) lsasum_check(h, body);
279 322

  
323
  log(L_WARN "Checksum result %4x", h->checksum);
324

  
280 325
  ntohlsah(h, h);
281
  ntohlsab(body, body, h->type, length - sizeof(struct ospf_lsa_header));
326
  ntohlsab(body, body, type, length - sizeof(struct ospf_lsa_header));
282 327
}
283 328

  
284 329
/*
......
294 339
  u16 length;
295 340

  
296 341
  b = body;
297
  sp = (char *) &h;
342
  sp = (char *) h;
298 343
  sp += 2; /* Skip Age field */
299 344
  length = ntohs(h->length) - 2;
300 345
  h->checksum = 0;

Also available in: Unified diff