Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / lsreq.c @ 29239ba2

History | View | Annotate | Download (3.5 KB)

1 6d2b3211 Ondrej Filip
/*
2
 *        BIRD -- OSPF
3
 *
4 27f49a2c Ondrej Filip
 *        (c) 2000--2004 Ondrej Filip <feela@network.cz>
5 70945cb6 Ondrej Zajicek
 *        (c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org>
6
 *        (c) 2009--2014 CZ.NIC z.s.p.o.
7 6d2b3211 Ondrej Filip
 *
8
 *        Can be freely distributed and used under the terms of the GNU GPL.
9
 */
10
11
#include "ospf.h"
12
13 c3226991 Ondrej Zajicek
14 70945cb6 Ondrej Zajicek
/*
15 c3226991 Ondrej Zajicek
struct ospf_lsreq_packet
16
{
17 70945cb6 Ondrej Zajicek
  struct ospf_packet hdr;
18
  // union ospf_auth auth;
19

20
  struct ospf_lsreq_header lsrs[];
21 c3226991 Ondrej Zajicek
};
22 70945cb6 Ondrej Zajicek
*/
23 c3226991 Ondrej Zajicek
24
25 70945cb6 Ondrej Zajicek
static inline void
26
ospf_lsreq_body(struct ospf_proto *p, struct ospf_packet *pkt,
27
                struct ospf_lsreq_header **body, uint *count)
28 8298d780 Ondrej Zajicek
{
29 70945cb6 Ondrej Zajicek
  uint plen = ntohs(pkt->length);
30
  uint hlen = ospf_pkt_hdrlen(p);
31
32
  *body = ((void *) pkt) + hlen;
33
  *count = (plen - hlen) / sizeof(struct ospf_lsreq_header);
34
}
35 8298d780 Ondrej Zajicek
36 70945cb6 Ondrej Zajicek
static void
37
ospf_dump_lsreq(struct ospf_proto *p, struct ospf_packet *pkt)
38
{
39
  struct ospf_lsreq_header *lsrs;
40
  uint i, lsr_count;
41 8298d780 Ondrej Zajicek
42 70945cb6 Ondrej Zajicek
  ASSERT(pkt->type == LSREQ_P);
43
  ospf_dump_common(p, pkt);
44 8298d780 Ondrej Zajicek
45 70945cb6 Ondrej Zajicek
  ospf_lsreq_body(p, pkt, &lsrs, &lsr_count);
46
  for (i = 0; i < lsr_count; i++)
47
    log(L_TRACE "%s:     LSR      Type: %04x, Id: %R, Rt: %R", p->p.name,
48
        ntohl(lsrs[i].type), ntohl(lsrs[i].id), ntohl(lsrs[i].rt));
49 8298d780 Ondrej Zajicek
}
50
51 70945cb6 Ondrej Zajicek
52 6d2b3211 Ondrej Filip
void
53 70945cb6 Ondrej Zajicek
ospf_send_lsreq(struct ospf_proto *p, struct ospf_neighbor *n)
54 6d2b3211 Ondrej Filip
{
55 70945cb6 Ondrej Zajicek
  struct ospf_iface *ifa = n->ifa;
56
  struct ospf_lsreq_header *lsrs;
57 6f8bbaa1 Ondrej Zajicek
  struct top_hash_entry *req;
58 70945cb6 Ondrej Zajicek
  struct ospf_packet *pkt;
59
  uint i, lsr_max, length;
60 6d2b3211 Ondrej Filip
61 70945cb6 Ondrej Zajicek
  /* RFC 2328 10.9 */
62 6d2b3211 Ondrej Filip
63 6f8bbaa1 Ondrej Zajicek
  /* ASSERT((n->state >= NEIGHBOR_EXCHANGE) && !EMPTY_SLIST(n->lsrql)); */
64 27f49a2c Ondrej Filip
65 70945cb6 Ondrej Zajicek
  pkt = ospf_tx_buffer(ifa);
66
  ospf_pkt_fill_hdr(ifa, pkt, LSREQ_P);
67
  ospf_lsreq_body(p, pkt, &lsrs, &lsr_max);
68
69
  i = 0;
70 6f8bbaa1 Ondrej Zajicek
  WALK_SLIST(req, n->lsrql)
71 6d2b3211 Ondrej Filip
  {
72 70945cb6 Ondrej Zajicek
    if (i == lsr_max)
73 27f49a2c Ondrej Filip
      break;
74 70945cb6 Ondrej Zajicek
75
    DBG("Requesting %uth LSA: Type: %04u, ID: %R, RT: %R, SN: 0x%x, Age %u\n",
76 6f8bbaa1 Ondrej Zajicek
        i, req->lsa_type, req->lsa.id, req->lsa.rt, req->lsa.sn, req->lsa.age);
77 70945cb6 Ondrej Zajicek
78 6f8bbaa1 Ondrej Zajicek
    u32 etype = lsa_get_etype(&req->lsa, p);
79 70945cb6 Ondrej Zajicek
    lsrs[i].type = htonl(etype);
80 6f8bbaa1 Ondrej Zajicek
    lsrs[i].rt = htonl(req->lsa.rt);
81
    lsrs[i].id = htonl(req->lsa.id);
82 70945cb6 Ondrej Zajicek
    i++;
83 6d2b3211 Ondrej Filip
  }
84
85 6f8bbaa1 Ondrej Zajicek
  /* We store the position to see whether requested LSAs have been received */
86
  n->lsrqi = req;
87
88 70945cb6 Ondrej Zajicek
  length = ospf_pkt_hdrlen(p) + i * sizeof(struct ospf_lsreq_header);
89
  pkt->length = htons(length);
90 8298d780 Ondrej Zajicek
91 f8fefde3 Ondrej Zajicek
  OSPF_PACKET(ospf_dump_lsreq, pkt, "LSREQ packet sent to nbr %R on %s", n->rid, ifa->ifname);
92 70945cb6 Ondrej Zajicek
  ospf_send_to(ifa, n->ip);
93 6d2b3211 Ondrej Filip
}
94
95 70945cb6 Ondrej Zajicek
96 6d2b3211 Ondrej Filip
void
97 70945cb6 Ondrej Zajicek
ospf_receive_lsreq(struct ospf_packet *pkt, struct ospf_iface *ifa,
98 c3226991 Ondrej Zajicek
                   struct ospf_neighbor *n)
99 6d2b3211 Ondrej Filip
{
100 70945cb6 Ondrej Zajicek
  struct ospf_proto *p = ifa->oa->po;
101
  struct ospf_lsreq_header *lsrs;
102
  uint i, lsr_count;
103 a6bc04d5 Ondrej Zajicek
104 70945cb6 Ondrej Zajicek
  /* RFC 2328 10.7 */
105
106
  /* No need to check length, lsreq has only basic header */
107
108 f8fefde3 Ondrej Zajicek
  OSPF_PACKET(ospf_dump_lsreq, pkt, "LSREQ packet received from nbr %R on %s", n->rid, ifa->ifname);
109 8298d780 Ondrej Zajicek
110 27f49a2c Ondrej Filip
  if (n->state < NEIGHBOR_EXCHANGE)
111 f8fefde3 Ondrej Zajicek
  {
112
    OSPF_TRACE(D_PACKETS, "LSREQ packet ignored - lesser state than Exchange");
113 27f49a2c Ondrej Filip
    return;
114 f8fefde3 Ondrej Zajicek
  }
115 9669362f Ondrej Filip
116 70945cb6 Ondrej Zajicek
  ospf_neigh_sm(n, INM_HELLOREC);        /* Not in RFC */
117
118
  ospf_lsreq_body(p, pkt, &lsrs, &lsr_count);
119 6d2b3211 Ondrej Filip
120 70945cb6 Ondrej Zajicek
  struct top_hash_entry *en, *entries[lsr_count];
121 f45fd316 Ondrej Filip
122 70945cb6 Ondrej Zajicek
  for (i = 0; i < lsr_count; i++)
123 6d2b3211 Ondrej Filip
  {
124 70945cb6 Ondrej Zajicek
    u32 id, rt, type, domain;
125
126
    id = ntohl(lsrs[i].id);
127
    rt = ntohl(lsrs[i].rt);
128
    lsa_get_type_domain_(ntohl(lsrs[i].type), ifa, &type, &domain);
129
130
    DBG("Processing requested LSA: Type: %04x, Id: %R, Rt: %R\n", type, id, rt);
131
132 742029eb Ondrej Zajicek
    en = ospf_hash_find(p->gr, domain, id, rt, type);
133 70945cb6 Ondrej Zajicek
    if (!en)
134 de769e24 Ondrej Filip
    {
135 f8fefde3 Ondrej Zajicek
      LOG_LSA1("Bad LSR (Type: %04x, Id: %R, Rt: %R) in LSREQ", type, id, rt);
136
      LOG_LSA2("  received from nbr %R on %s - LSA is missing", n->rid, ifa->ifname);
137
138 27f49a2c Ondrej Filip
      ospf_neigh_sm(n, INM_BADLSREQ);
139 de769e24 Ondrej Filip
      return;
140
    }
141 70945cb6 Ondrej Zajicek
142
    entries[i] = en;
143 6d2b3211 Ondrej Filip
  }
144 70945cb6 Ondrej Zajicek
145
  ospf_send_lsupd(p, entries, lsr_count, n);
146 6d2b3211 Ondrej Filip
}