2 * OSPF Sending and Receiving OSPF Packets.
3 * Copyright (C) 1999, 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 #include "sockunion.h"
38 #include "ospfd/ospfd.h"
39 #include "ospfd/ospf_network.h"
40 #include "ospfd/ospf_interface.h"
41 #include "ospfd/ospf_ism.h"
42 #include "ospfd/ospf_asbr.h"
43 #include "ospfd/ospf_lsa.h"
44 #include "ospfd/ospf_lsdb.h"
45 #include "ospfd/ospf_neighbor.h"
46 #include "ospfd/ospf_nsm.h"
47 #include "ospfd/ospf_packet.h"
48 #include "ospfd/ospf_spf.h"
49 #include "ospfd/ospf_flood.h"
50 #include "ospfd/ospf_dump.h"
52 /* Packet Type String. */
53 const char *ospf_packet_type_str
[] =
57 "Database Description",
60 "Link State Acknowledgment",
63 /* OSPF authentication checking function */
65 ospf_auth_type (struct ospf_interface
*oi
)
69 if (OSPF_IF_PARAM (oi
, auth_type
) == OSPF_AUTH_NOTSET
)
70 auth_type
= oi
->area
->auth_type
;
72 auth_type
= OSPF_IF_PARAM (oi
, auth_type
);
74 /* Handle case where MD5 key list is not configured aka Cisco */
75 if (auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
&&
76 list_isempty (OSPF_IF_PARAM (oi
, auth_crypt
)))
77 return OSPF_AUTH_NULL
;
84 ospf_packet_new (size_t size
)
86 struct ospf_packet
*new;
88 new = XCALLOC (MTYPE_OSPF_PACKET
, sizeof (struct ospf_packet
));
89 new->s
= stream_new (size
);
95 ospf_packet_free (struct ospf_packet
*op
)
100 XFREE (MTYPE_OSPF_PACKET
, op
);
108 struct ospf_fifo
*new;
110 new = XCALLOC (MTYPE_OSPF_FIFO
, sizeof (struct ospf_fifo
));
114 /* Add new packet to fifo. */
116 ospf_fifo_push (struct ospf_fifo
*fifo
, struct ospf_packet
*op
)
119 fifo
->tail
->next
= op
;
128 /* Delete first packet from fifo. */
130 ospf_fifo_pop (struct ospf_fifo
*fifo
)
132 struct ospf_packet
*op
;
138 fifo
->head
= op
->next
;
140 if (fifo
->head
== NULL
)
149 /* Return first fifo entry. */
151 ospf_fifo_head (struct ospf_fifo
*fifo
)
156 /* Flush ospf packet fifo. */
158 ospf_fifo_flush (struct ospf_fifo
*fifo
)
160 struct ospf_packet
*op
;
161 struct ospf_packet
*next
;
163 for (op
= fifo
->head
; op
; op
= next
)
166 ospf_packet_free (op
);
168 fifo
->head
= fifo
->tail
= NULL
;
172 /* Free ospf packet fifo. */
174 ospf_fifo_free (struct ospf_fifo
*fifo
)
176 ospf_fifo_flush (fifo
);
178 XFREE (MTYPE_OSPF_FIFO
, fifo
);
182 ospf_packet_add (struct ospf_interface
*oi
, struct ospf_packet
*op
)
186 zlog_err("ospf_packet_add(interface %s in state %d [%s], packet type %s, "
187 "destination %s) called with NULL obuf, ignoring "
188 "(please report this bug)!\n",
189 IF_NAME(oi
), oi
->state
, LOOKUP (ospf_ism_state_msg
, oi
->state
),
190 ospf_packet_type_str
[stream_getc_from(op
->s
, 1)],
191 inet_ntoa (op
->dst
));
195 /* Add packet to end of queue. */
196 ospf_fifo_push (oi
->obuf
, op
);
198 /* Debug of packet fifo*/
199 /* ospf_fifo_debug (oi->obuf); */
203 ospf_packet_delete (struct ospf_interface
*oi
)
205 struct ospf_packet
*op
;
207 op
= ospf_fifo_pop (oi
->obuf
);
210 ospf_packet_free (op
);
214 ospf_packet_dup (struct ospf_packet
*op
)
216 struct ospf_packet
*new;
218 if (stream_get_endp(op
->s
) != op
->length
)
220 zlog_warn ("ospf_packet_dup stream %lu ospf_packet %u size mismatch",
221 (u_long
)STREAM_SIZE(op
->s
), op
->length
);
223 /* Reserve space for MD5 authentication that may be added later. */
224 new = ospf_packet_new (stream_get_endp(op
->s
) + OSPF_AUTH_MD5_SIZE
);
225 stream_copy (new->s
, op
->s
);
228 new->length
= op
->length
;
234 static inline unsigned int
235 ospf_packet_authspace (struct ospf_interface
*oi
)
239 if ( ospf_auth_type (oi
) == OSPF_AUTH_CRYPTOGRAPHIC
)
240 auth
= OSPF_AUTH_MD5_SIZE
;
246 ospf_packet_max (struct ospf_interface
*oi
)
250 max
= oi
->ifp
->mtu
- ospf_packet_authspace(oi
);
252 max
-= (OSPF_HEADER_SIZE
+ sizeof (struct ip
));
259 ospf_check_md5_digest (struct ospf_interface
*oi
, struct stream
*s
,
264 unsigned char digest
[OSPF_AUTH_MD5_SIZE
];
265 unsigned char *pdigest
;
266 struct crypt_key
*ck
;
267 struct ospf_header
*ospfh
;
268 struct ospf_neighbor
*nbr
;
271 ibuf
= STREAM_PNT (s
);
272 ospfh
= (struct ospf_header
*) ibuf
;
274 /* Get pointer to the end of the packet. */
275 pdigest
= ibuf
+ length
;
277 /* Get secret key. */
278 ck
= ospf_crypt_key_lookup (OSPF_IF_PARAM (oi
, auth_crypt
),
279 ospfh
->u
.crypt
.key_id
);
282 zlog_warn ("interface %s: ospf_check_md5 no key %d",
283 IF_NAME (oi
), ospfh
->u
.crypt
.key_id
);
287 /* check crypto seqnum. */
288 nbr
= ospf_nbr_lookup_by_routerid (oi
->nbrs
, &ospfh
->router_id
);
290 if (nbr
&& ntohl(nbr
->crypt_seqnum
) > ntohl(ospfh
->u
.crypt
.crypt_seqnum
))
292 zlog_warn ("interface %s: ospf_check_md5 bad sequence %d (expect %d)",
294 ntohl(ospfh
->u
.crypt
.crypt_seqnum
),
295 ntohl(nbr
->crypt_seqnum
));
299 /* Generate a digest for the ospf packet - their digest + our digest. */
300 memset(&ctx
, 0, sizeof(ctx
));
302 MD5Update(&ctx
, ibuf
, length
);
303 MD5Update(&ctx
, ck
->auth_key
, OSPF_AUTH_MD5_SIZE
);
304 MD5Final(digest
, &ctx
);
306 /* compare the two */
307 if (memcmp (pdigest
, digest
, OSPF_AUTH_MD5_SIZE
))
309 zlog_warn ("interface %s: ospf_check_md5 checksum mismatch",
314 /* save neighbor's crypt_seqnum */
316 nbr
->crypt_seqnum
= ospfh
->u
.crypt
.crypt_seqnum
;
320 /* This function is called from ospf_write(), it will detect the
321 authentication scheme and if it is MD5, it will change the sequence
322 and update the MD5 digest. */
324 ospf_make_md5_digest (struct ospf_interface
*oi
, struct ospf_packet
*op
)
326 struct ospf_header
*ospfh
;
327 unsigned char digest
[OSPF_AUTH_MD5_SIZE
];
331 struct crypt_key
*ck
;
332 const u_int8_t
*auth_key
;
334 ibuf
= STREAM_DATA (op
->s
);
335 ospfh
= (struct ospf_header
*) ibuf
;
337 if (ntohs (ospfh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
340 /* We do this here so when we dup a packet, we don't have to
341 waste CPU rewriting other headers.
343 Note that quagga_time /deliberately/ is not used here */
344 t
= (time(NULL
) & 0xFFFFFFFF);
345 if (t
> oi
->crypt_seqnum
)
346 oi
->crypt_seqnum
= t
;
350 ospfh
->u
.crypt
.crypt_seqnum
= htonl (oi
->crypt_seqnum
);
352 /* Get MD5 Authentication key from auth_key list. */
353 if (list_isempty (OSPF_IF_PARAM (oi
, auth_crypt
)))
354 auth_key
= (const u_int8_t
*) "";
357 ck
= listgetdata (listtail(OSPF_IF_PARAM (oi
, auth_crypt
)));
358 auth_key
= ck
->auth_key
;
361 /* Generate a digest for the entire packet + our secret key. */
362 memset(&ctx
, 0, sizeof(ctx
));
364 MD5Update(&ctx
, ibuf
, ntohs (ospfh
->length
));
365 MD5Update(&ctx
, auth_key
, OSPF_AUTH_MD5_SIZE
);
366 MD5Final(digest
, &ctx
);
368 /* Append md5 digest to the end of the stream. */
369 stream_put (op
->s
, digest
, OSPF_AUTH_MD5_SIZE
);
371 /* We do *NOT* increment the OSPF header length. */
372 op
->length
= ntohs (ospfh
->length
) + OSPF_AUTH_MD5_SIZE
;
374 if (stream_get_endp(op
->s
) != op
->length
)
376 zlog_warn("ospf_make_md5_digest: length mismatch stream %lu ospf_packet %u",
377 (u_long
)stream_get_endp(op
->s
), op
->length
);
379 return OSPF_AUTH_MD5_SIZE
;
384 ospf_ls_req_timer (struct thread
*thread
)
386 struct ospf_neighbor
*nbr
;
388 nbr
= THREAD_ARG (thread
);
389 nbr
->t_ls_req
= NULL
;
391 /* Send Link State Request. */
392 if (ospf_ls_request_count (nbr
))
393 ospf_ls_req_send (nbr
);
395 /* Set Link State Request retransmission timer. */
396 OSPF_NSM_TIMER_ON (nbr
->t_ls_req
, ospf_ls_req_timer
, nbr
->v_ls_req
);
402 ospf_ls_req_event (struct ospf_neighbor
*nbr
)
406 thread_cancel (nbr
->t_ls_req
);
407 nbr
->t_ls_req
= NULL
;
409 nbr
->t_ls_req
= thread_add_event (master
, ospf_ls_req_timer
, nbr
, 0);
412 /* Cyclic timer function. Fist registered in ospf_nbr_new () in
415 ospf_ls_upd_timer (struct thread
*thread
)
417 struct ospf_neighbor
*nbr
;
419 nbr
= THREAD_ARG (thread
);
420 nbr
->t_ls_upd
= NULL
;
422 /* Send Link State Update. */
423 if (ospf_ls_retransmit_count (nbr
) > 0)
426 struct ospf_lsdb
*lsdb
;
428 int retransmit_interval
;
430 retransmit_interval
= OSPF_IF_PARAM (nbr
->oi
, retransmit_interval
);
432 lsdb
= &nbr
->ls_rxmt
;
433 update
= list_new ();
435 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
437 struct route_table
*table
= lsdb
->type
[i
].db
;
438 struct route_node
*rn
;
440 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
442 struct ospf_lsa
*lsa
;
444 if ((lsa
= rn
->info
) != NULL
)
445 /* Don't retransmit an LSA if we received it within
446 the last RxmtInterval seconds - this is to allow the
447 neighbour a chance to acknowledge the LSA as it may
448 have ben just received before the retransmit timer
449 fired. This is a small tweak to what is in the RFC,
450 but it will cut out out a lot of retransmit traffic
452 if (tv_cmp (tv_sub (recent_relative_time (), lsa
->tv_recv
),
453 int2tv (retransmit_interval
)) >= 0)
454 listnode_add (update
, rn
->info
);
458 if (listcount (update
) > 0)
459 ospf_ls_upd_send (nbr
, update
, OSPF_SEND_PACKET_DIRECT
);
460 list_delete (update
);
463 /* Set LS Update retransmission timer. */
464 OSPF_NSM_TIMER_ON (nbr
->t_ls_upd
, ospf_ls_upd_timer
, nbr
->v_ls_upd
);
470 ospf_ls_ack_timer (struct thread
*thread
)
472 struct ospf_interface
*oi
;
474 oi
= THREAD_ARG (thread
);
477 /* Send Link State Acknowledgment. */
478 if (listcount (oi
->ls_ack
) > 0)
479 ospf_ls_ack_send_delayed (oi
);
481 /* Set LS Ack timer. */
482 OSPF_ISM_TIMER_ON (oi
->t_ls_ack
, ospf_ls_ack_timer
, oi
->v_ls_ack
);
487 #ifdef WANT_OSPF_WRITE_FRAGMENT
489 ospf_write_frags (int fd
, struct ospf_packet
*op
, struct ip
*iph
,
490 struct msghdr
*msg
, unsigned int maxdatasize
,
491 unsigned int mtu
, int flags
, u_char type
)
493 #define OSPF_WRITE_FRAG_SHIFT 3
498 assert ( op
->length
== stream_get_endp(op
->s
) );
499 assert (msg
->msg_iovlen
== 2);
503 * SunOS, BSD and BSD derived kernels likely will clear ip_id, as
504 * well as the IP_MF flag, making this all quite pointless.
506 * However, for a system on which IP_MF is left alone, and ip_id left
507 * alone or else which sets same ip_id for each fragment this might
510 * XXX-TODO: It would be much nicer to have the kernel's use their
511 * existing fragmentation support to do this for us. Bugs/RFEs need to
512 * be raised against the various kernels.
516 iph
->ip_off
|= IP_MF
;
518 /* ip frag offset is expressed in units of 8byte words */
519 offset
= maxdatasize
>> OSPF_WRITE_FRAG_SHIFT
;
521 iovp
= &msg
->msg_iov
[1];
523 while ( (stream_get_endp(op
->s
) - stream_get_getp (op
->s
))
526 /* data length of this frag is to next offset value */
527 iovp
->iov_len
= offset
<< OSPF_WRITE_FRAG_SHIFT
;
528 iph
->ip_len
= iovp
->iov_len
+ sizeof (struct ip
);
529 assert (iph
->ip_len
<= mtu
);
531 sockopt_iphdrincl_swab_htosys (iph
);
533 ret
= sendmsg (fd
, msg
, flags
);
535 sockopt_iphdrincl_swab_systoh (iph
);
538 zlog_warn ("*** ospf_write_frags: sendmsg failed to %s,"
539 " id %d, off %d, len %d, mtu %u failed with %s",
540 inet_ntoa (iph
->ip_dst
),
545 safe_strerror (errno
));
547 if (IS_DEBUG_OSPF_PACKET (type
- 1, SEND
))
549 zlog_debug ("ospf_write_frags: sent id %d, off %d, len %d to %s\n",
550 iph
->ip_id
, iph
->ip_off
, iph
->ip_len
,
551 inet_ntoa (iph
->ip_dst
));
552 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
554 zlog_debug ("-----------------IP Header Dump----------------------");
555 ospf_ip_header_dump (iph
);
556 zlog_debug ("-----------------------------------------------------");
560 iph
->ip_off
+= offset
;
561 stream_forward_getp (op
->s
, iovp
->iov_len
);
562 iovp
->iov_base
= STREAM_PNT (op
->s
);
565 /* setup for final fragment */
566 iovp
->iov_len
= stream_get_endp(op
->s
) - stream_get_getp (op
->s
);
567 iph
->ip_len
= iovp
->iov_len
+ sizeof (struct ip
);
568 iph
->ip_off
&= (~IP_MF
);
570 #endif /* WANT_OSPF_WRITE_FRAGMENT */
573 ospf_write (struct thread
*thread
)
575 struct ospf
*ospf
= THREAD_ARG (thread
);
576 struct ospf_interface
*oi
;
577 struct ospf_packet
*op
;
578 struct sockaddr_in sa_dst
;
585 struct listnode
*node
;
586 #ifdef WANT_OSPF_WRITE_FRAGMENT
587 static u_int16_t ipid
= 0;
588 #endif /* WANT_OSPF_WRITE_FRAGMENT */
589 u_int16_t maxdatasize
;
590 #define OSPF_WRITE_IPHL_SHIFT 2
592 ospf
->t_write
= NULL
;
594 node
= listhead (ospf
->oi_write_q
);
596 oi
= listgetdata (node
);
599 #ifdef WANT_OSPF_WRITE_FRAGMENT
600 /* seed ipid static with low order bits of time */
602 ipid
= (time(NULL
) & 0xffff);
603 #endif /* WANT_OSPF_WRITE_FRAGMENT */
605 /* convenience - max OSPF data per packet,
606 * and reliability - not more data, than our
609 maxdatasize
= MIN (oi
->ifp
->mtu
, ospf
->maxsndbuflen
) -
612 /* Get one packet from queue. */
613 op
= ospf_fifo_head (oi
->obuf
);
615 assert (op
->length
>= OSPF_HEADER_SIZE
);
617 if (op
->dst
.s_addr
== htonl (OSPF_ALLSPFROUTERS
)
618 || op
->dst
.s_addr
== htonl (OSPF_ALLDROUTERS
))
619 ospf_if_ipmulticast (ospf
, oi
->address
, oi
->ifp
->ifindex
);
621 /* Rewrite the md5 signature & update the seq */
622 ospf_make_md5_digest (oi
, op
);
624 /* Retrieve OSPF packet type. */
625 stream_set_getp (op
->s
, 1);
626 type
= stream_getc (op
->s
);
628 /* reset get pointer */
629 stream_set_getp (op
->s
, 0);
631 memset (&iph
, 0, sizeof (struct ip
));
632 memset (&sa_dst
, 0, sizeof (sa_dst
));
634 sa_dst
.sin_family
= AF_INET
;
635 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
636 sa_dst
.sin_len
= sizeof(sa_dst
);
637 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
638 sa_dst
.sin_addr
= op
->dst
;
639 sa_dst
.sin_port
= htons (0);
641 /* Set DONTROUTE flag if dst is unicast. */
642 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
643 if (!IN_MULTICAST (htonl (op
->dst
.s_addr
)))
644 flags
= MSG_DONTROUTE
;
646 iph
.ip_hl
= sizeof (struct ip
) >> OSPF_WRITE_IPHL_SHIFT
;
647 /* it'd be very strange for header to not be 4byte-word aligned but.. */
648 if ( sizeof (struct ip
)
649 > (unsigned int)(iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
) )
650 iph
.ip_hl
++; /* we presume sizeof struct ip cant overflow ip_hl.. */
652 iph
.ip_v
= IPVERSION
;
653 iph
.ip_tos
= IPTOS_PREC_INTERNETCONTROL
;
654 iph
.ip_len
= (iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
) + op
->length
;
656 #ifdef WANT_OSPF_WRITE_FRAGMENT
657 /* XXX-MT: not thread-safe at all..
658 * XXX: this presumes this is only programme sending OSPF packets
659 * otherwise, no guarantee ipid will be unique
662 #endif /* WANT_OSPF_WRITE_FRAGMENT */
665 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
666 iph
.ip_ttl
= OSPF_VL_IP_TTL
;
668 iph
.ip_ttl
= OSPF_IP_TTL
;
669 iph
.ip_p
= IPPROTO_OSPFIGP
;
671 iph
.ip_src
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
672 iph
.ip_dst
.s_addr
= op
->dst
.s_addr
;
674 memset (&msg
, 0, sizeof (msg
));
675 msg
.msg_name
= (caddr_t
) &sa_dst
;
676 msg
.msg_namelen
= sizeof (sa_dst
);
679 iov
[0].iov_base
= (char*)&iph
;
680 iov
[0].iov_len
= iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
;
681 iov
[1].iov_base
= STREAM_PNT (op
->s
);
682 iov
[1].iov_len
= op
->length
;
684 /* Sadly we can not rely on kernels to fragment packets because of either
685 * IP_HDRINCL and/or multicast destination being set.
687 #ifdef WANT_OSPF_WRITE_FRAGMENT
688 if ( op
->length
> maxdatasize
)
689 ospf_write_frags (ospf
->fd
, op
, &iph
, &msg
, maxdatasize
,
690 oi
->ifp
->mtu
, flags
, type
);
691 #endif /* WANT_OSPF_WRITE_FRAGMENT */
693 /* send final fragment (could be first) */
694 sockopt_iphdrincl_swab_htosys (&iph
);
695 ret
= sendmsg (ospf
->fd
, &msg
, flags
);
696 sockopt_iphdrincl_swab_systoh (&iph
);
699 zlog_warn ("*** sendmsg in ospf_write failed to %s, "
700 "id %d, off %d, len %d, interface %s, mtu %u: %s",
701 inet_ntoa (iph
.ip_dst
), iph
.ip_id
, iph
.ip_off
, iph
.ip_len
,
702 oi
->ifp
->name
, oi
->ifp
->mtu
, safe_strerror (errno
));
704 /* Show debug sending packet. */
705 if (IS_DEBUG_OSPF_PACKET (type
- 1, SEND
))
707 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
709 zlog_debug ("-----------------------------------------------------");
710 ospf_ip_header_dump (&iph
);
711 stream_set_getp (op
->s
, 0);
712 ospf_packet_dump (op
->s
);
715 zlog_debug ("%s sent to [%s] via [%s].",
716 ospf_packet_type_str
[type
], inet_ntoa (op
->dst
),
719 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
720 zlog_debug ("-----------------------------------------------------");
723 /* Now delete packet from queue. */
724 ospf_packet_delete (oi
);
726 if (ospf_fifo_head (oi
->obuf
) == NULL
)
729 list_delete_node (ospf
->oi_write_q
, node
);
732 /* If packets still remain in queue, call write thread. */
733 if (!list_isempty (ospf
->oi_write_q
))
735 thread_add_write (master
, ospf_write
, ospf
, ospf
->fd
);
740 /* OSPF Hello message read -- RFC2328 Section 10.5. */
742 ospf_hello (struct ip
*iph
, struct ospf_header
*ospfh
,
743 struct stream
* s
, struct ospf_interface
*oi
, int size
)
745 struct ospf_hello
*hello
;
746 struct ospf_neighbor
*nbr
;
750 /* increment statistics. */
753 hello
= (struct ospf_hello
*) STREAM_PNT (s
);
755 /* If Hello is myself, silently discard. */
756 if (IPV4_ADDR_SAME (&ospfh
->router_id
, &oi
->ospf
->router_id
))
758 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
760 zlog_debug ("ospf_header[%s/%s]: selforiginated, "
762 ospf_packet_type_str
[ospfh
->type
],
763 inet_ntoa (iph
->ip_src
));
768 /* get neighbor prefix. */
770 p
.prefixlen
= ip_masklen (hello
->network_mask
);
771 p
.u
.prefix4
= iph
->ip_src
;
773 /* Compare network mask. */
774 /* Checking is ignored for Point-to-Point and Virtual link. */
775 if (oi
->type
!= OSPF_IFTYPE_POINTOPOINT
776 && oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
777 if (oi
->address
->prefixlen
!= p
.prefixlen
)
779 zlog_warn ("Packet %s [Hello:RECV]: NetworkMask mismatch on %s (configured prefix length is %d, but hello packet indicates %d).",
780 inet_ntoa(ospfh
->router_id
), IF_NAME(oi
),
781 (int)oi
->address
->prefixlen
, (int)p
.prefixlen
);
785 /* Compare Router Dead Interval. */
786 if (OSPF_IF_PARAM (oi
, v_wait
) != ntohl (hello
->dead_interval
))
788 zlog_warn ("Packet %s [Hello:RECV]: RouterDeadInterval mismatch "
789 "(expected %u, but received %u).",
790 inet_ntoa(ospfh
->router_id
),
791 OSPF_IF_PARAM(oi
, v_wait
), ntohl(hello
->dead_interval
));
795 /* Compare Hello Interval - ignored if fast-hellos are set. */
796 if (OSPF_IF_PARAM (oi
, fast_hello
) == 0)
798 if (OSPF_IF_PARAM (oi
, v_hello
) != ntohs (hello
->hello_interval
))
800 zlog_warn ("Packet %s [Hello:RECV]: HelloInterval mismatch "
801 "(expected %u, but received %u).",
802 inet_ntoa(ospfh
->router_id
),
803 OSPF_IF_PARAM(oi
, v_hello
), ntohs(hello
->hello_interval
));
808 if (IS_DEBUG_OSPF_EVENT
)
809 zlog_debug ("Packet %s [Hello:RECV]: Options %s",
810 inet_ntoa (ospfh
->router_id
),
811 ospf_options_dump (hello
->options
));
813 /* Compare options. */
814 #define REJECT_IF_TBIT_ON 1 /* XXX */
815 #ifdef REJECT_IF_TBIT_ON
816 if (CHECK_FLAG (hello
->options
, OSPF_OPTION_T
))
819 * This router does not support non-zero TOS.
820 * Drop this Hello packet not to establish neighbor relationship.
822 zlog_warn ("Packet %s [Hello:RECV]: T-bit on, drop it.",
823 inet_ntoa (ospfh
->router_id
));
826 #endif /* REJECT_IF_TBIT_ON */
828 #ifdef HAVE_OPAQUE_LSA
829 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
)
830 && CHECK_FLAG (hello
->options
, OSPF_OPTION_O
))
833 * This router does know the correct usage of O-bit
834 * the bit should be set in DD packet only.
836 zlog_warn ("Packet %s [Hello:RECV]: O-bit abuse?",
837 inet_ntoa (ospfh
->router_id
));
838 #ifdef STRICT_OBIT_USAGE_CHECK
839 return; /* Reject this packet. */
840 #else /* STRICT_OBIT_USAGE_CHECK */
841 UNSET_FLAG (hello
->options
, OSPF_OPTION_O
); /* Ignore O-bit. */
842 #endif /* STRICT_OBIT_USAGE_CHECK */
844 #endif /* HAVE_OPAQUE_LSA */
846 /* new for NSSA is to ensure that NP is on and E is off */
848 if (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
850 if (! (CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_NP
)
851 && CHECK_FLAG (hello
->options
, OSPF_OPTION_NP
)
852 && ! CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_E
)
853 && ! CHECK_FLAG (hello
->options
, OSPF_OPTION_E
)))
855 zlog_warn ("NSSA-Packet-%s[Hello:RECV]: my options: %x, his options %x", inet_ntoa (ospfh
->router_id
), OPTIONS (oi
), hello
->options
);
858 if (IS_DEBUG_OSPF_NSSA
)
859 zlog_debug ("NSSA-Hello:RECV:Packet from %s:", inet_ntoa(ospfh
->router_id
));
862 /* The setting of the E-bit found in the Hello Packet's Options
863 field must match this area's ExternalRoutingCapability A
864 mismatch causes processing to stop and the packet to be
865 dropped. The setting of the rest of the bits in the Hello
866 Packet's Options field should be ignored. */
867 if (CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_E
) !=
868 CHECK_FLAG (hello
->options
, OSPF_OPTION_E
))
870 zlog_warn ("Packet %s [Hello:RECV]: my options: %x, his options %x",
871 inet_ntoa(ospfh
->router_id
), OPTIONS (oi
), hello
->options
);
875 /* get neighbour struct */
876 nbr
= ospf_nbr_get (oi
, ospfh
, iph
, &p
);
878 /* neighbour must be valid, ospf_nbr_get creates if none existed */
881 old_state
= nbr
->state
;
883 /* Add event to thread. */
884 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_HelloReceived
);
886 /* RFC2328 Section 9.5.1
887 If the router is not eligible to become Designated Router,
888 (snip) It must also send an Hello Packet in reply to an
889 Hello Packet received from any eligible neighbor (other than
890 the current Designated Router and Backup Designated Router). */
891 if (oi
->type
== OSPF_IFTYPE_NBMA
)
892 if (PRIORITY(oi
) == 0 && hello
->priority
> 0
893 && IPV4_ADDR_CMP(&DR(oi
), &iph
->ip_src
)
894 && IPV4_ADDR_CMP(&BDR(oi
), &iph
->ip_src
))
895 OSPF_NSM_TIMER_ON (nbr
->t_hello_reply
, ospf_hello_reply_timer
,
896 OSPF_HELLO_REPLY_DELAY
);
898 /* on NBMA network type, it happens to receive bidirectional Hello packet
899 without advance 1-Way Received event.
900 To avoid incorrect DR-seletion, raise 1-Way Received event.*/
901 if (oi
->type
== OSPF_IFTYPE_NBMA
&&
902 (old_state
== NSM_Down
|| old_state
== NSM_Attempt
))
904 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_OneWayReceived
);
905 nbr
->priority
= hello
->priority
;
906 nbr
->d_router
= hello
->d_router
;
907 nbr
->bd_router
= hello
->bd_router
;
911 if (ospf_nbr_bidirectional (&oi
->ospf
->router_id
, hello
->neighbors
,
912 size
- OSPF_HELLO_MIN_SIZE
))
914 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_TwoWayReceived
);
915 nbr
->options
|= hello
->options
;
919 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_OneWayReceived
);
920 /* Set neighbor information. */
921 nbr
->priority
= hello
->priority
;
922 nbr
->d_router
= hello
->d_router
;
923 nbr
->bd_router
= hello
->bd_router
;
927 /* If neighbor itself declares DR and no BDR exists,
928 cause event BackupSeen */
929 if (IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->d_router
))
930 if (hello
->bd_router
.s_addr
== 0 && oi
->state
== ISM_Waiting
)
931 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_BackupSeen
);
933 /* neighbor itself declares BDR. */
934 if (oi
->state
== ISM_Waiting
&&
935 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->bd_router
))
936 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_BackupSeen
);
938 /* had not previously. */
939 if ((IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->d_router
) &&
940 IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &nbr
->d_router
)) ||
941 (IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &hello
->d_router
) &&
942 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &nbr
->d_router
)))
943 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
945 /* had not previously. */
946 if ((IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->bd_router
) &&
947 IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &nbr
->bd_router
)) ||
948 (IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &hello
->bd_router
) &&
949 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &nbr
->bd_router
)))
950 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
952 /* Neighbor priority check. */
953 if (nbr
->priority
>= 0 && nbr
->priority
!= hello
->priority
)
954 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
956 /* Set neighbor information. */
957 nbr
->priority
= hello
->priority
;
958 nbr
->d_router
= hello
->d_router
;
959 nbr
->bd_router
= hello
->bd_router
;
962 /* Save DD flags/options/Seqnum received. */
964 ospf_db_desc_save_current (struct ospf_neighbor
*nbr
,
965 struct ospf_db_desc
*dd
)
967 nbr
->last_recv
.flags
= dd
->flags
;
968 nbr
->last_recv
.options
= dd
->options
;
969 nbr
->last_recv
.dd_seqnum
= ntohl (dd
->dd_seqnum
);
972 /* Process rest of DD packet. */
974 ospf_db_desc_proc (struct stream
*s
, struct ospf_interface
*oi
,
975 struct ospf_neighbor
*nbr
, struct ospf_db_desc
*dd
,
978 struct ospf_lsa
*new, *find
;
979 struct lsa_header
*lsah
;
981 stream_forward_getp (s
, OSPF_DB_DESC_MIN_SIZE
);
982 for (size
-= OSPF_DB_DESC_MIN_SIZE
;
983 size
>= OSPF_LSA_HEADER_SIZE
; size
-= OSPF_LSA_HEADER_SIZE
)
985 lsah
= (struct lsa_header
*) STREAM_PNT (s
);
986 stream_forward_getp (s
, OSPF_LSA_HEADER_SIZE
);
988 /* Unknown LS type. */
989 if (lsah
->type
< OSPF_MIN_LSA
|| lsah
->type
>= OSPF_MAX_LSA
)
991 zlog_warn ("Packet [DD:RECV]: Unknown LS type %d.", lsah
->type
);
992 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
996 #ifdef HAVE_OPAQUE_LSA
997 if (IS_OPAQUE_LSA (lsah
->type
)
998 && ! CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
1000 zlog_warn ("LSA[Type%d:%s]: Opaque capability mismatch?", lsah
->type
, inet_ntoa (lsah
->id
));
1001 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1004 #endif /* HAVE_OPAQUE_LSA */
1008 case OSPF_AS_EXTERNAL_LSA
:
1009 #ifdef HAVE_OPAQUE_LSA
1010 case OSPF_OPAQUE_AS_LSA
:
1011 #endif /* HAVE_OPAQUE_LSA */
1012 /* Check for stub area. Reject if AS-External from stub but
1013 allow if from NSSA. */
1014 if (oi
->area
->external_routing
== OSPF_AREA_STUB
)
1016 zlog_warn ("Packet [DD:RECV]: LSA[Type%d:%s] from %s area.",
1017 lsah
->type
, inet_ntoa (lsah
->id
),
1018 (oi
->area
->external_routing
== OSPF_AREA_STUB
) ?\
1020 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1028 /* Create LS-request object. */
1029 new = ospf_ls_request_new (lsah
);
1031 /* Lookup received LSA, then add LS request list. */
1032 find
= ospf_lsa_lookup_by_header (oi
->area
, lsah
);
1034 /* ospf_lsa_more_recent is fine with NULL pointers */
1035 switch (ospf_lsa_more_recent (find
, new))
1038 /* Neighbour has a more recent LSA, we must request it */
1039 ospf_ls_request_add (nbr
, new);
1041 /* If we have a copy of this LSA, it's either less recent
1042 * and we're requesting it from neighbour (the case above), or
1043 * it's as recent and we both have same copy (this case).
1045 * In neither of these two cases is there any point in
1046 * describing our copy of the LSA to the neighbour in a
1047 * DB-Summary packet, if we're still intending to do so.
1049 * See: draft-ogier-ospf-dbex-opt-00.txt, describing the
1050 * backward compatible optimisation to OSPF DB Exchange /
1051 * DB Description process implemented here.
1054 ospf_lsdb_delete (&nbr
->db_sum
, find
);
1055 ospf_lsa_discard (new);
1058 /* We have the more recent copy, nothing specific to do:
1059 * - no need to request neighbours stale copy
1060 * - must leave DB summary list copy alone
1062 if (IS_DEBUG_OSPF_EVENT
)
1063 zlog_debug ("Packet [DD:RECV]: LSA received Type %d, "
1064 "ID %s is not recent.", lsah
->type
, inet_ntoa (lsah
->id
));
1065 ospf_lsa_discard (new);
1070 if (IS_SET_DD_MS (nbr
->dd_flags
))
1074 /* Both sides have no More, then we're done with Exchange */
1075 if (!IS_SET_DD_M (dd
->flags
) && !IS_SET_DD_M (nbr
->dd_flags
))
1076 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_ExchangeDone
);
1078 ospf_db_desc_send (nbr
);
1083 nbr
->dd_seqnum
= ntohl (dd
->dd_seqnum
);
1085 /* Send DD packet in reply.
1087 * Must be done to acknowledge the Master's DD, regardless of
1088 * whether we have more LSAs ourselves to describe.
1090 * This function will clear the 'More' bit, if after this DD
1091 * we have no more LSAs to describe to the master..
1093 ospf_db_desc_send (nbr
);
1095 /* Slave can raise ExchangeDone now, if master is also done */
1096 if (!IS_SET_DD_M (dd
->flags
) && !IS_SET_DD_M (nbr
->dd_flags
))
1097 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_ExchangeDone
);
1100 /* Save received neighbor values from DD. */
1101 ospf_db_desc_save_current (nbr
, dd
);
1105 ospf_db_desc_is_dup (struct ospf_db_desc
*dd
, struct ospf_neighbor
*nbr
)
1107 /* Is DD duplicated? */
1108 if (dd
->options
== nbr
->last_recv
.options
&&
1109 dd
->flags
== nbr
->last_recv
.flags
&&
1110 dd
->dd_seqnum
== htonl (nbr
->last_recv
.dd_seqnum
))
1116 /* OSPF Database Description message read -- RFC2328 Section 10.6. */
1118 ospf_db_desc (struct ip
*iph
, struct ospf_header
*ospfh
,
1119 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1121 struct ospf_db_desc
*dd
;
1122 struct ospf_neighbor
*nbr
;
1124 /* Increment statistics. */
1127 dd
= (struct ospf_db_desc
*) STREAM_PNT (s
);
1129 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1132 zlog_warn ("Packet[DD]: Unknown Neighbor %s",
1133 inet_ntoa (ospfh
->router_id
));
1138 if ((OSPF_IF_PARAM (oi
, mtu_ignore
) == 0) &&
1139 (ntohs (dd
->mtu
) > oi
->ifp
->mtu
))
1141 zlog_warn ("Packet[DD]: Neighbor %s MTU %u is larger than [%s]'s MTU %u",
1142 inet_ntoa (nbr
->router_id
), ntohs (dd
->mtu
),
1143 IF_NAME (oi
), oi
->ifp
->mtu
);
1148 * XXX HACK by Hasso Tepper. Setting N/P bit in NSSA area DD packets is not
1149 * required. In fact at least JunOS sends DD packets with P bit clear.
1150 * Until proper solution is developped, this hack should help.
1152 * Update: According to the RFCs, N bit is specified /only/ for Hello
1153 * options, unfortunately its use in DD options is not specified. Hence some
1154 * implementations follow E-bit semantics and set it in DD options, and some
1155 * treat it as unspecified and hence follow the directive "default for
1156 * options is clear", ie unset.
1158 * Reset the flag, as ospfd follows E-bit semantics.
1160 if ( (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
1161 && (CHECK_FLAG (nbr
->options
, OSPF_OPTION_NP
))
1162 && (!CHECK_FLAG (dd
->options
, OSPF_OPTION_NP
)) )
1164 if (IS_DEBUG_OSPF_EVENT
)
1165 zlog_debug ("Packet[DD]: Neighbour %s: Has NSSA capability, sends with N bit clear in DD options",
1166 inet_ntoa (nbr
->router_id
) );
1167 SET_FLAG (dd
->options
, OSPF_OPTION_NP
);
1170 #ifdef REJECT_IF_TBIT_ON
1171 if (CHECK_FLAG (dd
->options
, OSPF_OPTION_T
))
1174 * In Hello protocol, optional capability must have checked
1175 * to prevent this T-bit enabled router be my neighbor.
1177 zlog_warn ("Packet[DD]: Neighbor %s: T-bit on?", inet_ntoa (nbr
->router_id
));
1180 #endif /* REJECT_IF_TBIT_ON */
1182 #ifdef HAVE_OPAQUE_LSA
1183 if (CHECK_FLAG (dd
->options
, OSPF_OPTION_O
)
1184 && !CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
1187 * This node is not configured to handle O-bit, for now.
1188 * Clear it to ignore unsupported capability proposed by neighbor.
1190 UNSET_FLAG (dd
->options
, OSPF_OPTION_O
);
1192 #endif /* HAVE_OPAQUE_LSA */
1194 /* Process DD packet by neighbor status. */
1200 zlog_warn ("Packet[DD]: Neighbor %s state is %s, packet discarded.",
1201 inet_ntoa(nbr
->router_id
),
1202 LOOKUP (ospf_nsm_state_msg
, nbr
->state
));
1205 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_TwoWayReceived
);
1206 /* If the new state is ExStart, the processing of the current
1207 packet should then continue in this new state by falling
1208 through to case ExStart below. */
1209 if (nbr
->state
!= NSM_ExStart
)
1213 if ((IS_SET_DD_ALL (dd
->flags
) == OSPF_DD_FLAG_ALL
) &&
1214 (size
== OSPF_DB_DESC_MIN_SIZE
))
1216 if (IPV4_ADDR_CMP (&nbr
->router_id
, &oi
->ospf
->router_id
) > 0)
1218 /* We're Slave---obey */
1219 zlog_info ("Packet[DD]: Neighbor %s Negotiation done (Slave).",
1220 inet_ntoa(nbr
->router_id
));
1221 nbr
->dd_seqnum
= ntohl (dd
->dd_seqnum
);
1224 UNSET_FLAG (nbr
->dd_flags
, (OSPF_DD_FLAG_MS
|OSPF_DD_FLAG_I
));
1228 /* We're Master, ignore the initial DBD from Slave */
1229 zlog_info ("Packet[DD]: Neighbor %s: Initial DBD from Slave, "
1230 "ignoring.", inet_ntoa(nbr
->router_id
));
1234 /* Ack from the Slave */
1235 else if (!IS_SET_DD_MS (dd
->flags
) && !IS_SET_DD_I (dd
->flags
) &&
1236 ntohl (dd
->dd_seqnum
) == nbr
->dd_seqnum
&&
1237 IPV4_ADDR_CMP (&nbr
->router_id
, &oi
->ospf
->router_id
) < 0)
1239 zlog_info ("Packet[DD]: Neighbor %s Negotiation done (Master).",
1240 inet_ntoa(nbr
->router_id
));
1241 /* Reset I, leaving MS */
1242 UNSET_FLAG (nbr
->dd_flags
, OSPF_DD_FLAG_I
);
1246 zlog_warn ("Packet[DD]: Neighbor %s Negotiation fails.",
1247 inet_ntoa(nbr
->router_id
));
1251 /* This is where the real Options are saved */
1252 nbr
->options
= dd
->options
;
1254 #ifdef HAVE_OPAQUE_LSA
1255 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
1257 if (IS_DEBUG_OSPF_EVENT
)
1258 zlog_debug ("Neighbor[%s] is %sOpaque-capable.",
1259 inet_ntoa (nbr
->router_id
),
1260 CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
) ? "" : "NOT ");
1262 if (! CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
)
1263 && IPV4_ADDR_SAME (&DR (oi
), &nbr
->address
.u
.prefix4
))
1265 zlog_warn ("DR-neighbor[%s] is NOT opaque-capable; "
1266 "Opaque-LSAs cannot be reliably advertised "
1268 inet_ntoa (nbr
->router_id
));
1269 /* This situation is undesirable, but not a real error. */
1272 #endif /* HAVE_OPAQUE_LSA */
1274 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_NegotiationDone
);
1276 /* continue processing rest of packet. */
1277 ospf_db_desc_proc (s
, oi
, nbr
, dd
, size
);
1280 if (ospf_db_desc_is_dup (dd
, nbr
))
1282 if (IS_SET_DD_MS (nbr
->dd_flags
))
1283 /* Master: discard duplicated DD packet. */
1284 zlog_info ("Packet[DD] (Master): Neighbor %s packet duplicated.",
1285 inet_ntoa (nbr
->router_id
));
1287 /* Slave: cause to retransmit the last Database Description. */
1289 zlog_info ("Packet[DD] [Slave]: Neighbor %s packet duplicated.",
1290 inet_ntoa (nbr
->router_id
));
1291 ospf_db_desc_resend (nbr
);
1296 /* Otherwise DD packet should be checked. */
1297 /* Check Master/Slave bit mismatch */
1298 if (IS_SET_DD_MS (dd
->flags
) != IS_SET_DD_MS (nbr
->last_recv
.flags
))
1300 zlog_warn ("Packet[DD]: Neighbor %s MS-bit mismatch.",
1301 inet_ntoa(nbr
->router_id
));
1302 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1303 if (IS_DEBUG_OSPF_EVENT
)
1304 zlog_debug ("Packet[DD]: dd->flags=%d, nbr->dd_flags=%d",
1305 dd
->flags
, nbr
->dd_flags
);
1309 /* Check initialize bit is set. */
1310 if (IS_SET_DD_I (dd
->flags
))
1312 zlog_info ("Packet[DD]: Neighbor %s I-bit set.",
1313 inet_ntoa(nbr
->router_id
));
1314 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1318 /* Check DD Options. */
1319 if (dd
->options
!= nbr
->options
)
1321 #ifdef ORIGINAL_CODING
1322 /* Save the new options for debugging */
1323 nbr
->options
= dd
->options
;
1324 #endif /* ORIGINAL_CODING */
1325 zlog_warn ("Packet[DD]: Neighbor %s options mismatch.",
1326 inet_ntoa(nbr
->router_id
));
1327 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1331 /* Check DD sequence number. */
1332 if ((IS_SET_DD_MS (nbr
->dd_flags
) &&
1333 ntohl (dd
->dd_seqnum
) != nbr
->dd_seqnum
) ||
1334 (!IS_SET_DD_MS (nbr
->dd_flags
) &&
1335 ntohl (dd
->dd_seqnum
) != nbr
->dd_seqnum
+ 1))
1337 zlog_warn ("Packet[DD]: Neighbor %s sequence number mismatch.",
1338 inet_ntoa(nbr
->router_id
));
1339 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1343 /* Continue processing rest of packet. */
1344 ospf_db_desc_proc (s
, oi
, nbr
, dd
, size
);
1348 if (ospf_db_desc_is_dup (dd
, nbr
))
1350 if (IS_SET_DD_MS (nbr
->dd_flags
))
1352 /* Master should discard duplicate DD packet. */
1353 zlog_info ("Packet[DD]: Neighbor %s duplicated, "
1354 "packet discarded.",
1355 inet_ntoa(nbr
->router_id
));
1360 struct timeval t
, now
;
1361 quagga_gettime (QUAGGA_CLK_MONOTONIC
, &now
);
1362 t
= tv_sub (now
, nbr
->last_send_ts
);
1363 if (tv_cmp (t
, int2tv (nbr
->v_inactivity
)) < 0)
1365 /* In states Loading and Full the slave must resend
1366 its last Database Description packet in response to
1367 duplicate Database Description packets received
1368 from the master. For this reason the slave must
1369 wait RouterDeadInterval seconds before freeing the
1370 last Database Description packet. Reception of a
1371 Database Description packet from the master after
1372 this interval will generate a SeqNumberMismatch
1373 neighbor event. RFC2328 Section 10.8 */
1374 ospf_db_desc_resend (nbr
);
1380 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1383 zlog_warn ("Packet[DD]: Neighbor %s NSM illegal status %u.",
1384 inet_ntoa(nbr
->router_id
), nbr
->state
);
1389 #define OSPF_LSA_KEY_SIZE 12 /* type(4) + id(4) + ar(4) */
1391 /* OSPF Link State Request Read -- RFC2328 Section 10.7. */
1393 ospf_ls_req (struct ip
*iph
, struct ospf_header
*ospfh
,
1394 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1396 struct ospf_neighbor
*nbr
;
1398 struct in_addr ls_id
;
1399 struct in_addr adv_router
;
1400 struct ospf_lsa
*find
;
1401 struct list
*ls_upd
;
1402 unsigned int length
;
1404 /* Increment statistics. */
1407 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1410 zlog_warn ("Link State Request: Unknown Neighbor %s.",
1411 inet_ntoa (ospfh
->router_id
));
1415 /* Neighbor State should be Exchange or later. */
1416 if (nbr
->state
!= NSM_Exchange
&&
1417 nbr
->state
!= NSM_Loading
&&
1418 nbr
->state
!= NSM_Full
)
1420 zlog_warn ("Link State Request received from %s: "
1421 "Neighbor state is %s, packet discarded.",
1422 inet_ntoa (ospfh
->router_id
),
1423 LOOKUP (ospf_nsm_state_msg
, nbr
->state
));
1427 /* Send Link State Update for ALL requested LSAs. */
1428 ls_upd
= list_new ();
1429 length
= OSPF_HEADER_SIZE
+ OSPF_LS_UPD_MIN_SIZE
;
1431 while (size
>= OSPF_LSA_KEY_SIZE
)
1433 /* Get one slice of Link State Request. */
1434 ls_type
= stream_getl (s
);
1435 ls_id
.s_addr
= stream_get_ipv4 (s
);
1436 adv_router
.s_addr
= stream_get_ipv4 (s
);
1438 /* Verify LSA type. */
1439 if (ls_type
< OSPF_MIN_LSA
|| ls_type
>= OSPF_MAX_LSA
)
1441 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
1442 list_delete (ls_upd
);
1446 /* Search proper LSA in LSDB. */
1447 find
= ospf_lsa_lookup (oi
->area
, ls_type
, ls_id
, adv_router
);
1450 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
1451 list_delete (ls_upd
);
1455 /* Packet overflows MTU size, send immediately. */
1456 if (length
+ ntohs (find
->data
->length
) > ospf_packet_max (oi
))
1458 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1459 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_DIRECT
);
1461 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_INDIRECT
);
1463 /* Only remove list contents. Keep ls_upd. */
1464 list_delete_all_node (ls_upd
);
1466 length
= OSPF_HEADER_SIZE
+ OSPF_LS_UPD_MIN_SIZE
;
1469 /* Append LSA to update list. */
1470 listnode_add (ls_upd
, find
);
1471 length
+= ntohs (find
->data
->length
);
1473 size
-= OSPF_LSA_KEY_SIZE
;
1476 /* Send rest of Link State Update. */
1477 if (listcount (ls_upd
) > 0)
1479 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1480 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_DIRECT
);
1482 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_INDIRECT
);
1484 list_delete (ls_upd
);
1490 /* Get the list of LSAs from Link State Update packet.
1491 And process some validation -- RFC2328 Section 13. (1)-(2). */
1492 static struct list
*
1493 ospf_ls_upd_list_lsa (struct ospf_neighbor
*nbr
, struct stream
*s
,
1494 struct ospf_interface
*oi
, size_t size
)
1496 u_int16_t count
, sum
;
1498 struct lsa_header
*lsah
;
1499 struct ospf_lsa
*lsa
;
1504 count
= stream_getl (s
);
1505 size
-= OSPF_LS_UPD_MIN_SIZE
; /* # LSAs */
1507 for (; size
>= OSPF_LSA_HEADER_SIZE
&& count
> 0;
1508 size
-= length
, stream_forward_getp (s
, length
), count
--)
1510 lsah
= (struct lsa_header
*) STREAM_PNT (s
);
1511 length
= ntohs (lsah
->length
);
1515 zlog_warn ("Link State Update: LSA length exceeds packet size.");
1519 /* Validate the LSA's LS checksum. */
1520 sum
= lsah
->checksum
;
1521 if (sum
!= ospf_lsa_checksum (lsah
))
1523 zlog_warn ("Link State Update: LSA checksum error %x, %x.",
1524 sum
, lsah
->checksum
);
1528 /* Examine the LSA's LS type. */
1529 if (lsah
->type
< OSPF_MIN_LSA
|| lsah
->type
>= OSPF_MAX_LSA
)
1531 zlog_warn ("Link State Update: Unknown LS type %d", lsah
->type
);
1536 * What if the received LSA's age is greater than MaxAge?
1537 * Treat it as a MaxAge case -- endo.
1539 if (ntohs (lsah
->ls_age
) > OSPF_LSA_MAXAGE
)
1540 lsah
->ls_age
= htons (OSPF_LSA_MAXAGE
);
1542 #ifdef HAVE_OPAQUE_LSA
1543 if (CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
1545 #ifdef STRICT_OBIT_USAGE_CHECK
1546 if ((IS_OPAQUE_LSA(lsah
->type
) &&
1547 ! CHECK_FLAG (lsah
->options
, OSPF_OPTION_O
))
1548 || (! IS_OPAQUE_LSA(lsah
->type
) &&
1549 CHECK_FLAG (lsah
->options
, OSPF_OPTION_O
)))
1552 * This neighbor must know the exact usage of O-bit;
1553 * the bit will be set in Type-9,10,11 LSAs only.
1555 zlog_warn ("LSA[Type%d:%s]: O-bit abuse?", lsah
->type
, inet_ntoa (lsah
->id
));
1558 #endif /* STRICT_OBIT_USAGE_CHECK */
1560 /* Do not take in AS External Opaque-LSAs if we are a stub. */
1561 if (lsah
->type
== OSPF_OPAQUE_AS_LSA
1562 && nbr
->oi
->area
->external_routing
!= OSPF_AREA_DEFAULT
)
1564 if (IS_DEBUG_OSPF_EVENT
)
1565 zlog_debug ("LSA[Type%d:%s]: We are a stub, don't take this LSA.", lsah
->type
, inet_ntoa (lsah
->id
));
1569 else if (IS_OPAQUE_LSA(lsah
->type
))
1571 zlog_warn ("LSA[Type%d:%s]: Opaque capability mismatch?", lsah
->type
, inet_ntoa (lsah
->id
));
1574 #endif /* HAVE_OPAQUE_LSA */
1576 /* Create OSPF LSA instance. */
1577 lsa
= ospf_lsa_new ();
1579 /* We may wish to put some error checking if type NSSA comes in
1580 and area not in NSSA mode */
1583 case OSPF_AS_EXTERNAL_LSA
:
1584 #ifdef HAVE_OPAQUE_LSA
1585 case OSPF_OPAQUE_AS_LSA
:
1588 case OSPF_OPAQUE_LINK_LSA
:
1589 lsa
->oi
= oi
; /* Remember incoming interface for flooding control. */
1591 #endif /* HAVE_OPAQUE_LSA */
1593 lsa
->area
= oi
->area
;
1597 lsa
->data
= ospf_lsa_data_new (length
);
1598 memcpy (lsa
->data
, lsah
, length
);
1600 if (IS_DEBUG_OSPF_EVENT
)
1601 zlog_debug("LSA[Type%d:%s]: %p new LSA created with Link State Update",
1602 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), lsa
);
1603 listnode_add (lsas
, lsa
);
1609 /* Cleanup Update list. */
1611 ospf_upd_list_clean (struct list
*lsas
)
1613 struct listnode
*node
, *nnode
;
1614 struct ospf_lsa
*lsa
;
1616 for (ALL_LIST_ELEMENTS (lsas
, node
, nnode
, lsa
))
1617 ospf_lsa_discard (lsa
);
1622 /* OSPF Link State Update message read -- RFC2328 Section 13. */
1624 ospf_ls_upd (struct ip
*iph
, struct ospf_header
*ospfh
,
1625 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1627 struct ospf_neighbor
*nbr
;
1629 struct listnode
*node
, *nnode
;
1630 struct ospf_lsa
*lsa
= NULL
;
1631 /* unsigned long ls_req_found = 0; */
1633 /* Dis-assemble the stream, update each entry, re-encapsulate for flooding */
1635 /* Increment statistics. */
1638 /* Check neighbor. */
1639 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1642 zlog_warn ("Link State Update: Unknown Neighbor %s on int: %s",
1643 inet_ntoa (ospfh
->router_id
), IF_NAME (oi
));
1647 /* Check neighbor state. */
1648 if (nbr
->state
< NSM_Exchange
)
1650 zlog_warn ("Link State Update: "
1651 "Neighbor[%s] state %s is less than Exchange",
1652 inet_ntoa (ospfh
->router_id
),
1653 LOOKUP(ospf_nsm_state_msg
, nbr
->state
));
1657 /* Get list of LSAs from Link State Update packet. - Also perorms Stages
1658 * 1 (validate LSA checksum) and 2 (check for LSA consistent type)
1661 lsas
= ospf_ls_upd_list_lsa (nbr
, s
, oi
, size
);
1663 #ifdef HAVE_OPAQUE_LSA
1665 * If self-originated Opaque-LSAs that have flooded before restart
1666 * are contained in the received LSUpd message, corresponding LSReq
1667 * messages to be sent may have to be modified.
1668 * To eliminate possible race conditions such that flushing and normal
1669 * updating for the same LSA would take place alternately, this trick
1670 * must be done before entering to the loop below.
1672 /* XXX: Why is this Opaque specific? Either our core code is deficient
1673 * and this should be fixed generally, or Opaque is inventing strawman
1675 ospf_opaque_adjust_lsreq (nbr
, lsas
);
1676 #endif /* HAVE_OPAQUE_LSA */
1678 #define DISCARD_LSA(L,N) {\
1679 if (IS_DEBUG_OSPF_EVENT) \
1680 zlog_debug ("ospf_lsa_discard() in ospf_ls_upd() point %d: lsa %p Type-%d", N, lsa, (int) lsa->data->type); \
1681 ospf_lsa_discard (L); \
1684 /* Process each LSA received in the one packet. */
1685 for (ALL_LIST_ELEMENTS (lsas
, node
, nnode
, lsa
))
1687 struct ospf_lsa
*ls_ret
, *current
;
1690 if (IS_DEBUG_OSPF_NSSA
)
1692 char buf1
[INET_ADDRSTRLEN
];
1693 char buf2
[INET_ADDRSTRLEN
];
1694 char buf3
[INET_ADDRSTRLEN
];
1696 zlog_debug("LSA Type-%d from %s, ID: %s, ADV: %s",
1698 inet_ntop (AF_INET
, &ospfh
->router_id
,
1699 buf1
, INET_ADDRSTRLEN
),
1700 inet_ntop (AF_INET
, &lsa
->data
->id
,
1701 buf2
, INET_ADDRSTRLEN
),
1702 inet_ntop (AF_INET
, &lsa
->data
->adv_router
,
1703 buf3
, INET_ADDRSTRLEN
));
1706 listnode_delete (lsas
, lsa
); /* We don't need it in list anymore */
1708 /* Validate Checksum - Done above by ospf_ls_upd_list_lsa() */
1710 /* LSA Type - Done above by ospf_ls_upd_list_lsa() */
1712 /* Do not take in AS External LSAs if we are a stub or NSSA. */
1714 /* Do not take in AS NSSA if this neighbor and we are not NSSA */
1716 /* Do take in Type-7's if we are an NSSA */
1718 /* If we are also an ABR, later translate them to a Type-5 packet */
1720 /* Later, an NSSA Re-fresh can Re-fresh Type-7's and an ABR will
1721 translate them to a separate Type-5 packet. */
1723 if (lsa
->data
->type
== OSPF_AS_EXTERNAL_LSA
)
1724 /* Reject from STUB or NSSA */
1725 if (nbr
->oi
->area
->external_routing
!= OSPF_AREA_DEFAULT
)
1727 DISCARD_LSA (lsa
, 1);
1728 if (IS_DEBUG_OSPF_NSSA
)
1729 zlog_debug("Incoming External LSA Discarded: We are NSSA/STUB Area");
1732 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
)
1733 if (nbr
->oi
->area
->external_routing
!= OSPF_AREA_NSSA
)
1735 DISCARD_LSA (lsa
,2);
1736 if (IS_DEBUG_OSPF_NSSA
)
1737 zlog_debug("Incoming NSSA LSA Discarded: Not NSSA Area");
1740 /* Find the LSA in the current database. */
1742 current
= ospf_lsa_lookup_by_header (oi
->area
, lsa
->data
);
1744 /* If the LSA's LS age is equal to MaxAge, and there is currently
1745 no instance of the LSA in the router's link state database,
1746 and none of router's neighbors are in states Exchange or Loading,
1747 then take the following actions. */
1749 if (IS_LSA_MAXAGE (lsa
) && !current
&&
1750 (ospf_nbr_count (oi
, NSM_Exchange
) +
1751 ospf_nbr_count (oi
, NSM_Loading
)) == 0)
1753 /* Response Link State Acknowledgment. */
1754 ospf_ls_ack_send (nbr
, lsa
);
1757 zlog_info ("Link State Update[%s]: LS age is equal to MaxAge.",
1759 DISCARD_LSA (lsa
, 3);
1762 #ifdef HAVE_OPAQUE_LSA
1763 if (IS_OPAQUE_LSA (lsa
->data
->type
)
1764 && IPV4_ADDR_SAME (&lsa
->data
->adv_router
, &oi
->ospf
->router_id
))
1767 * Even if initial flushing seems to be completed, there might
1768 * be a case that self-originated LSA with MaxAge still remain
1769 * in the routing domain.
1770 * Just send an LSAck message to cease retransmission.
1772 if (IS_LSA_MAXAGE (lsa
))
1774 zlog_warn ("LSA[%s]: Boomerang effect?", dump_lsa_key (lsa
));
1775 ospf_ls_ack_send (nbr
, lsa
);
1776 ospf_lsa_discard (lsa
);
1778 if (current
!= NULL
&& ! IS_LSA_MAXAGE (current
))
1779 ospf_opaque_lsa_refresh_schedule (current
);
1784 * If an instance of self-originated Opaque-LSA is not found
1785 * in the LSDB, there are some possible cases here.
1787 * 1) This node lost opaque-capability after restart.
1788 * 2) Else, a part of opaque-type is no more supported.
1789 * 3) Else, a part of opaque-id is no more supported.
1791 * Anyway, it is still this node's responsibility to flush it.
1792 * Otherwise, the LSA instance remains in the routing domain
1793 * until its age reaches to MaxAge.
1795 /* XXX: We should deal with this for *ALL* LSAs, not just opaque */
1796 if (current
== NULL
)
1798 if (IS_DEBUG_OSPF_EVENT
)
1799 zlog_debug ("LSA[%s]: Previously originated Opaque-LSA,"
1800 "not found in the LSDB.", dump_lsa_key (lsa
));
1802 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
1804 ospf_opaque_self_originated_lsa_received (nbr
, lsa
);
1805 ospf_ls_ack_send (nbr
, lsa
);
1810 #endif /* HAVE_OPAQUE_LSA */
1812 /* It might be happen that received LSA is self-originated network LSA, but
1813 * router ID is cahnged. So, we should check if LSA is a network-LSA whose
1814 * Link State ID is one of the router's own IP interface addresses but whose
1815 * Advertising Router is not equal to the router's own Router ID
1816 * According to RFC 2328 12.4.2 and 13.4 this LSA should be flushed.
1819 if(lsa
->data
->type
== OSPF_NETWORK_LSA
)
1821 struct listnode
*oinode
, *oinnode
;
1822 struct ospf_interface
*out_if
;
1825 for (ALL_LIST_ELEMENTS (oi
->ospf
->oiflist
, oinode
, oinnode
, out_if
))
1830 if((IPV4_ADDR_SAME(&out_if
->address
->u
.prefix4
, &lsa
->data
->id
)) &&
1831 (!(IPV4_ADDR_SAME(&oi
->ospf
->router_id
, &lsa
->data
->adv_router
))))
1833 if(out_if
->network_lsa_self
)
1835 ospf_lsa_flush_area(lsa
,out_if
->area
);
1836 if(IS_DEBUG_OSPF_EVENT
)
1837 zlog_debug ("ospf_lsa_discard() in ospf_ls_upd() point 9: lsa %p Type-%d",
1838 lsa
, (int) lsa
->data
->type
);
1839 ospf_lsa_discard (lsa
);
1849 /* (5) Find the instance of this LSA that is currently contained
1850 in the router's link state database. If there is no
1851 database copy, or the received LSA is more recent than
1852 the database copy the following steps must be performed. */
1854 if (current
== NULL
||
1855 (ret
= ospf_lsa_more_recent (current
, lsa
)) < 0)
1857 /* Actual flooding procedure. */
1858 if (ospf_flood (oi
->ospf
, nbr
, current
, lsa
) < 0) /* Trap NSSA later. */
1859 DISCARD_LSA (lsa
, 4);
1863 /* (6) Else, If there is an instance of the LSA on the sending
1864 neighbor's Link state request list, an error has occurred in
1865 the Database Exchange process. In this case, restart the
1866 Database Exchange process by generating the neighbor event
1867 BadLSReq for the sending neighbor and stop processing the
1868 Link State Update packet. */
1870 if (ospf_ls_request_lookup (nbr
, lsa
))
1872 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
1873 zlog_warn("LSA[%s] instance exists on Link state request list",
1876 /* Clean list of LSAs. */
1877 ospf_upd_list_clean (lsas
);
1878 /* this lsa is not on lsas list already. */
1879 ospf_lsa_discard (lsa
);
1883 /* If the received LSA is the same instance as the database copy
1884 (i.e., neither one is more recent) the following two steps
1885 should be performed: */
1889 /* If the LSA is listed in the Link state retransmission list
1890 for the receiving adjacency, the router itself is expecting
1891 an acknowledgment for this LSA. The router should treat the
1892 received LSA as an acknowledgment by removing the LSA from
1893 the Link state retransmission list. This is termed an
1894 "implied acknowledgment". */
1896 ls_ret
= ospf_ls_retransmit_lookup (nbr
, lsa
);
1900 ospf_ls_retransmit_delete (nbr
, ls_ret
);
1902 /* Delayed acknowledgment sent if advertisement received
1903 from Designated Router, otherwise do nothing. */
1904 if (oi
->state
== ISM_Backup
)
1905 if (NBR_IS_DR (nbr
))
1906 listnode_add (oi
->ls_ack
, ospf_lsa_lock (lsa
));
1908 DISCARD_LSA (lsa
, 5);
1911 /* Acknowledge the receipt of the LSA by sending a
1912 Link State Acknowledgment packet back out the receiving
1915 ospf_ls_ack_send (nbr
, lsa
);
1916 DISCARD_LSA (lsa
, 6);
1920 /* The database copy is more recent. If the database copy
1921 has LS age equal to MaxAge and LS sequence number equal to
1922 MaxSequenceNumber, simply discard the received LSA without
1923 acknowledging it. (In this case, the LSA's LS sequence number is
1924 wrapping, and the MaxSequenceNumber LSA must be completely
1925 flushed before any new LSA instance can be introduced). */
1927 else if (ret
> 0) /* Database copy is more recent */
1929 if (IS_LSA_MAXAGE (current
) &&
1930 current
->data
->ls_seqnum
== htonl (OSPF_MAX_SEQUENCE_NUMBER
))
1932 DISCARD_LSA (lsa
, 7);
1934 /* Otherwise, as long as the database copy has not been sent in a
1935 Link State Update within the last MinLSArrival seconds, send the
1936 database copy back to the sending neighbor, encapsulated within
1937 a Link State Update Packet. The Link State Update Packet should
1938 be sent directly to the neighbor. In so doing, do not put the
1939 database copy of the LSA on the neighbor's link state
1940 retransmission list, and do not acknowledge the received (less
1941 recent) LSA instance. */
1946 quagga_gettime (QUAGGA_CLK_MONOTONIC
, &now
);
1948 if (tv_cmp (tv_sub (now
, current
->tv_orig
),
1949 int2tv (OSPF_MIN_LS_ARRIVAL
)) > 0)
1950 /* Trap NSSA type later.*/
1951 ospf_ls_upd_send_lsa (nbr
, current
, OSPF_SEND_PACKET_DIRECT
);
1952 DISCARD_LSA (lsa
, 8);
1957 assert (listcount (lsas
) == 0);
1961 /* OSPF Link State Acknowledgment message read -- RFC2328 Section 13.7. */
1963 ospf_ls_ack (struct ip
*iph
, struct ospf_header
*ospfh
,
1964 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1966 struct ospf_neighbor
*nbr
;
1968 /* increment statistics. */
1971 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1974 zlog_warn ("Link State Acknowledgment: Unknown Neighbor %s.",
1975 inet_ntoa (ospfh
->router_id
));
1979 if (nbr
->state
< NSM_Exchange
)
1981 zlog_warn ("Link State Acknowledgment: "
1982 "Neighbor[%s] state %s is less than Exchange",
1983 inet_ntoa (ospfh
->router_id
),
1984 LOOKUP(ospf_nsm_state_msg
, nbr
->state
));
1988 while (size
>= OSPF_LSA_HEADER_SIZE
)
1990 struct ospf_lsa
*lsa
, *lsr
;
1992 lsa
= ospf_lsa_new ();
1993 lsa
->data
= (struct lsa_header
*) STREAM_PNT (s
);
1995 /* lsah = (struct lsa_header *) STREAM_PNT (s); */
1996 size
-= OSPF_LSA_HEADER_SIZE
;
1997 stream_forward_getp (s
, OSPF_LSA_HEADER_SIZE
);
1999 if (lsa
->data
->type
< OSPF_MIN_LSA
|| lsa
->data
->type
>= OSPF_MAX_LSA
)
2002 ospf_lsa_discard (lsa
);
2006 lsr
= ospf_ls_retransmit_lookup (nbr
, lsa
);
2008 if (lsr
!= NULL
&& lsr
->data
->ls_seqnum
== lsa
->data
->ls_seqnum
)
2010 #ifdef HAVE_OPAQUE_LSA
2011 if (IS_OPAQUE_LSA (lsr
->data
->type
))
2012 ospf_opaque_ls_ack_received (nbr
, lsr
);
2013 #endif /* HAVE_OPAQUE_LSA */
2015 ospf_ls_retransmit_delete (nbr
, lsr
);
2019 ospf_lsa_discard (lsa
);
2025 static struct stream
*
2026 ospf_recv_packet (int fd
, struct interface
**ifp
, struct stream
*ibuf
)
2031 unsigned int ifindex
= 0;
2033 /* Header and data both require alignment. */
2034 char buff
[CMSG_SPACE(SOPT_SIZE_CMSG_IFINDEX_IPV4())];
2037 memset (&msgh
, 0, sizeof (struct msghdr
));
2038 msgh
.msg_iov
= &iov
;
2039 msgh
.msg_iovlen
= 1;
2040 msgh
.msg_control
= (caddr_t
) buff
;
2041 msgh
.msg_controllen
= sizeof (buff
);
2043 ret
= stream_recvmsg (ibuf
, fd
, &msgh
, 0, OSPF_MAX_PACKET_SIZE
+1);
2046 zlog_warn("stream_recvmsg failed: %s", safe_strerror(errno
));
2049 if ((unsigned int)ret
< sizeof(iph
)) /* ret must be > 0 now */
2051 zlog_warn("ospf_recv_packet: discarding runt packet of length %d "
2052 "(ip header size is %u)",
2053 ret
, (u_int
)sizeof(iph
));
2057 /* Note that there should not be alignment problems with this assignment
2058 because this is at the beginning of the stream data buffer. */
2059 iph
= (struct ip
*) STREAM_DATA(ibuf
);
2060 sockopt_iphdrincl_swab_systoh (iph
);
2062 ip_len
= iph
->ip_len
;
2064 #if !defined(GNU_LINUX) && (OpenBSD < 200311)
2066 * Kernel network code touches incoming IP header parameters,
2067 * before protocol specific processing.
2069 * 1) Convert byteorder to host representation.
2070 * --> ip_len, ip_id, ip_off
2072 * 2) Adjust ip_len to strip IP header size!
2073 * --> If user process receives entire IP packet via RAW
2074 * socket, it must consider adding IP header size to
2075 * the "ip_len" field of "ip" structure.
2077 * For more details, see <netinet/ip_input.c>.
2079 ip_len
= ip_len
+ (iph
->ip_hl
<< 2);
2082 ifindex
= getsockopt_ifindex (AF_INET
, &msgh
);
2084 *ifp
= if_lookup_by_index (ifindex
);
2088 zlog_warn ("ospf_recv_packet read length mismatch: ip_len is %d, "
2089 "but recvmsg returned %d", ip_len
, ret
);
2096 static struct ospf_interface
*
2097 ospf_associate_packet_vl (struct ospf
*ospf
, struct interface
*ifp
,
2098 struct ip
*iph
, struct ospf_header
*ospfh
)
2100 struct ospf_interface
*rcv_oi
;
2101 struct ospf_vl_data
*vl_data
;
2102 struct ospf_area
*vl_area
;
2103 struct listnode
*node
;
2105 if (IN_MULTICAST (ntohl (iph
->ip_dst
.s_addr
)) ||
2106 !OSPF_IS_AREA_BACKBONE (ospfh
))
2109 /* look for local OSPF interface matching the destination
2110 * to determine Area ID. We presume therefore the destination address
2111 * is unique, or at least (for "unnumbered" links), not used in other
2114 if ((rcv_oi
= ospf_if_lookup_by_local_addr (ospf
, NULL
,
2115 iph
->ip_dst
)) == NULL
)
2118 for (ALL_LIST_ELEMENTS_RO (ospf
->vlinks
, node
, vl_data
))
2120 vl_area
= ospf_area_lookup_by_area_id (ospf
, vl_data
->vl_area_id
);
2124 if (OSPF_AREA_SAME (&vl_area
, &rcv_oi
->area
) &&
2125 IPV4_ADDR_SAME (&vl_data
->vl_peer
, &ospfh
->router_id
))
2127 if (IS_DEBUG_OSPF_EVENT
)
2128 zlog_debug ("associating packet with %s",
2129 IF_NAME (vl_data
->vl_oi
));
2130 if (! CHECK_FLAG (vl_data
->vl_oi
->ifp
->flags
, IFF_UP
))
2132 if (IS_DEBUG_OSPF_EVENT
)
2133 zlog_debug ("This VL is not up yet, sorry");
2137 return vl_data
->vl_oi
;
2141 if (IS_DEBUG_OSPF_EVENT
)
2142 zlog_debug ("couldn't find any VL to associate the packet with");
2148 ospf_check_area_id (struct ospf_interface
*oi
, struct ospf_header
*ospfh
)
2150 /* Check match the Area ID of the receiving interface. */
2151 if (OSPF_AREA_SAME (&oi
->area
, &ospfh
))
2157 /* Unbound socket will accept any Raw IP packets if proto is matched.
2158 To prevent it, compare src IP address and i/f address with masking
2159 i/f network mask. */
2161 ospf_check_network_mask (struct ospf_interface
*oi
, struct in_addr ip_src
)
2163 struct in_addr mask
, me
, him
;
2165 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
||
2166 oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
2169 masklen2ip (oi
->address
->prefixlen
, &mask
);
2171 me
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
2172 him
.s_addr
= ip_src
.s_addr
& mask
.s_addr
;
2174 if (IPV4_ADDR_SAME (&me
, &him
))
2181 ospf_check_auth (struct ospf_interface
*oi
, struct stream
*ibuf
,
2182 struct ospf_header
*ospfh
)
2185 struct crypt_key
*ck
;
2187 switch (ntohs (ospfh
->auth_type
))
2189 case OSPF_AUTH_NULL
:
2192 case OSPF_AUTH_SIMPLE
:
2193 if (!memcmp (OSPF_IF_PARAM (oi
, auth_simple
), ospfh
->u
.auth_data
, OSPF_AUTH_SIMPLE_SIZE
))
2198 case OSPF_AUTH_CRYPTOGRAPHIC
:
2199 if ((ck
= listgetdata (listtail(OSPF_IF_PARAM (oi
,auth_crypt
)))) == NULL
)
2205 /* This is very basic, the digest processing is elsewhere */
2206 if (ospfh
->u
.crypt
.auth_data_len
== OSPF_AUTH_MD5_SIZE
&&
2207 ospfh
->u
.crypt
.key_id
== ck
->key_id
&&
2208 ntohs (ospfh
->length
) + OSPF_AUTH_SIMPLE_SIZE
<= stream_get_size (ibuf
))
2222 ospf_check_sum (struct ospf_header
*ospfh
)
2227 /* clear auth_data for checksum. */
2228 memset (ospfh
->u
.auth_data
, 0, OSPF_AUTH_SIMPLE_SIZE
);
2230 /* keep checksum and clear. */
2231 sum
= ospfh
->checksum
;
2232 memset (&ospfh
->checksum
, 0, sizeof (u_int16_t
));
2234 /* calculate checksum. */
2235 ret
= in_cksum (ospfh
, ntohs (ospfh
->length
));
2239 zlog_info ("ospf_check_sum(): checksum mismatch, my %X, his %X",
2247 /* OSPF Header verification. */
2249 ospf_verify_header (struct stream
*ibuf
, struct ospf_interface
*oi
,
2250 struct ip
*iph
, struct ospf_header
*ospfh
)
2252 /* check version. */
2253 if (ospfh
->version
!= OSPF_VERSION
)
2255 zlog_warn ("interface %s: ospf_read version number mismatch.",
2260 /* Check Area ID. */
2261 if (!ospf_check_area_id (oi
, ospfh
))
2263 zlog_warn ("interface %s: ospf_read invalid Area ID %s.",
2264 IF_NAME (oi
), inet_ntoa (ospfh
->area_id
));
2268 /* Check network mask, Silently discarded. */
2269 if (! ospf_check_network_mask (oi
, iph
->ip_src
))
2271 zlog_warn ("interface %s: ospf_read network address is not same [%s]",
2272 IF_NAME (oi
), inet_ntoa (iph
->ip_src
));
2276 /* Check authentication. */
2277 if (ospf_auth_type (oi
) != ntohs (ospfh
->auth_type
))
2279 zlog_warn ("interface %s: auth-type mismatch, local %d, rcvd %d",
2280 IF_NAME (oi
), ospf_auth_type (oi
), ntohs (ospfh
->auth_type
));
2284 if (! ospf_check_auth (oi
, ibuf
, ospfh
))
2286 zlog_warn ("interface %s: ospf_read authentication failed.",
2291 /* if check sum is invalid, packet is discarded. */
2292 if (ntohs (ospfh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
2294 if (! ospf_check_sum (ospfh
))
2296 zlog_warn ("interface %s: ospf_read packet checksum error %s",
2297 IF_NAME (oi
), inet_ntoa (ospfh
->router_id
));
2303 if (ospfh
->checksum
!= 0)
2305 if (ospf_check_md5_digest (oi
, ibuf
, ntohs (ospfh
->length
)) == 0)
2307 zlog_warn ("interface %s: ospf_read md5 authentication failed.",
2316 /* Starting point of packet process function. */
2318 ospf_read (struct thread
*thread
)
2321 struct stream
*ibuf
;
2323 struct ospf_interface
*oi
;
2325 struct ospf_header
*ospfh
;
2327 struct interface
*ifp
;
2329 /* first of all get interface pointer. */
2330 ospf
= THREAD_ARG (thread
);
2332 /* prepare for next packet. */
2333 ospf
->t_read
= thread_add_read (master
, ospf_read
, ospf
, ospf
->fd
);
2335 /* read OSPF packet. */
2336 stream_reset(ospf
->ibuf
);
2337 if (!(ibuf
= ospf_recv_packet (ospf
->fd
, &ifp
, ospf
->ibuf
)))
2340 /* Note that there should not be alignment problems with this assignment
2341 because this is at the beginning of the stream data buffer. */
2342 iph
= (struct ip
*) STREAM_DATA (ibuf
);
2343 /* Note that sockopt_iphdrincl_swab_systoh was called in ospf_recv_packet. */
2346 /* Handle cases where the platform does not support retrieving the ifindex,
2347 and also platforms (such as Solaris 8) that claim to support ifindex
2348 retrieval but do not. */
2349 ifp
= if_lookup_address (iph
->ip_src
);
2354 /* IP Header dump. */
2355 if (IS_DEBUG_OSPF_PACKET(0, RECV
))
2356 ospf_ip_header_dump (iph
);
2358 /* Self-originated packet should be discarded silently. */
2359 if (ospf_if_lookup_by_local_addr (ospf
, NULL
, iph
->ip_src
))
2361 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2363 zlog_debug ("ospf_read[%s]: Dropping self-originated packet",
2364 inet_ntoa (iph
->ip_src
));
2369 /* Adjust size to message length. */
2370 stream_forward_getp (ibuf
, iph
->ip_hl
* 4);
2372 /* Get ospf packet header. */
2373 ospfh
= (struct ospf_header
*) STREAM_PNT (ibuf
);
2375 /* associate packet with ospf interface */
2376 oi
= ospf_if_lookup_recv_if (ospf
, iph
->ip_src
, ifp
);
2378 /* If incoming interface is passive one, ignore it. */
2379 if (oi
&& OSPF_IF_PASSIVE_STATUS (oi
) == OSPF_IF_PASSIVE
)
2381 char buf
[3][INET_ADDRSTRLEN
];
2383 if (IS_DEBUG_OSPF_EVENT
)
2384 zlog_debug ("ignoring packet from router %s sent to %s, "
2385 "received on a passive interface, %s",
2386 inet_ntop(AF_INET
, &ospfh
->router_id
, buf
[0], sizeof(buf
[0])),
2387 inet_ntop(AF_INET
, &iph
->ip_dst
, buf
[1], sizeof(buf
[1])),
2388 inet_ntop(AF_INET
, &oi
->address
->u
.prefix4
,
2389 buf
[2], sizeof(buf
[2])));
2391 if (iph
->ip_dst
.s_addr
== htonl(OSPF_ALLSPFROUTERS
))
2393 /* Try to fix multicast membership.
2394 * Some OS:es may have problems in this area,
2395 * make sure it is removed.
2397 OI_MEMBER_JOINED(oi
, MEMBER_ALLROUTERS
);
2398 ospf_if_set_multicast(oi
);
2404 /* if no local ospf_interface,
2405 * or header area is backbone but ospf_interface is not
2406 * check for VLINK interface
2408 if ( (oi
== NULL
) ||
2409 (OSPF_IS_AREA_ID_BACKBONE(ospfh
->area_id
)
2410 && !OSPF_IS_AREA_ID_BACKBONE(oi
->area
->area_id
))
2413 if ((oi
= ospf_associate_packet_vl (ospf
, ifp
, iph
, ospfh
)) == NULL
)
2415 if (IS_DEBUG_OSPF_EVENT
)
2416 zlog_debug ("Packet from [%s] received on link %s"
2417 " but no ospf_interface",
2418 inet_ntoa (iph
->ip_src
), ifp
->name
);
2423 /* else it must be a local ospf interface, check it was received on
2426 else if (oi
->ifp
!= ifp
)
2428 if (IS_DEBUG_OSPF_EVENT
)
2429 zlog_warn ("Packet from [%s] received on wrong link %s",
2430 inet_ntoa (iph
->ip_src
), ifp
->name
);
2433 else if (oi
->state
== ISM_Down
)
2435 char buf
[2][INET_ADDRSTRLEN
];
2436 zlog_warn ("Ignoring packet from %s to %s received on interface that is "
2437 "down [%s]; interface flags are %s",
2438 inet_ntop(AF_INET
, &iph
->ip_src
, buf
[0], sizeof(buf
[0])),
2439 inet_ntop(AF_INET
, &iph
->ip_dst
, buf
[1], sizeof(buf
[1])),
2440 ifp
->name
, if_flag_dump(ifp
->flags
));
2441 /* Fix multicast memberships? */
2442 if (iph
->ip_dst
.s_addr
== htonl(OSPF_ALLSPFROUTERS
))
2443 OI_MEMBER_JOINED(oi
, MEMBER_ALLROUTERS
);
2444 else if (iph
->ip_dst
.s_addr
== htonl(OSPF_ALLDROUTERS
))
2445 OI_MEMBER_JOINED(oi
, MEMBER_DROUTERS
);
2446 if (oi
->multicast_memberships
)
2447 ospf_if_set_multicast(oi
);
2452 * If the received packet is destined for AllDRouters, the packet
2453 * should be accepted only if the received ospf interface state is
2454 * either DR or Backup -- endo.
2456 if (iph
->ip_dst
.s_addr
== htonl (OSPF_ALLDROUTERS
)
2457 && (oi
->state
!= ISM_DR
&& oi
->state
!= ISM_Backup
))
2459 zlog_warn ("Dropping packet for AllDRouters from [%s] via [%s] (ISM: %s)",
2460 inet_ntoa (iph
->ip_src
), IF_NAME (oi
),
2461 LOOKUP (ospf_ism_state_msg
, oi
->state
));
2462 /* Try to fix multicast membership. */
2463 SET_FLAG(oi
->multicast_memberships
, MEMBER_DROUTERS
);
2464 ospf_if_set_multicast(oi
);
2468 /* Show debug receiving packet. */
2469 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2471 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, DETAIL
))
2473 zlog_debug ("-----------------------------------------------------");
2474 ospf_packet_dump (ibuf
);
2477 zlog_debug ("%s received from [%s] via [%s]",
2478 ospf_packet_type_str
[ospfh
->type
],
2479 inet_ntoa (ospfh
->router_id
), IF_NAME (oi
));
2480 zlog_debug (" src [%s],", inet_ntoa (iph
->ip_src
));
2481 zlog_debug (" dst [%s]", inet_ntoa (iph
->ip_dst
));
2483 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, DETAIL
))
2484 zlog_debug ("-----------------------------------------------------");
2487 /* Some header verification. */
2488 ret
= ospf_verify_header (ibuf
, oi
, iph
, ospfh
);
2491 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2493 zlog_debug ("ospf_read[%s/%s]: Header check failed, "
2495 ospf_packet_type_str
[ospfh
->type
],
2496 inet_ntoa (iph
->ip_src
));
2501 stream_forward_getp (ibuf
, OSPF_HEADER_SIZE
);
2503 /* Adjust size to message length. */
2504 length
= ntohs (ospfh
->length
) - OSPF_HEADER_SIZE
;
2506 /* Read rest of the packet and call each sort of packet routine. */
2507 switch (ospfh
->type
)
2509 case OSPF_MSG_HELLO
:
2510 ospf_hello (iph
, ospfh
, ibuf
, oi
, length
);
2512 case OSPF_MSG_DB_DESC
:
2513 ospf_db_desc (iph
, ospfh
, ibuf
, oi
, length
);
2515 case OSPF_MSG_LS_REQ
:
2516 ospf_ls_req (iph
, ospfh
, ibuf
, oi
, length
);
2518 case OSPF_MSG_LS_UPD
:
2519 ospf_ls_upd (iph
, ospfh
, ibuf
, oi
, length
);
2521 case OSPF_MSG_LS_ACK
:
2522 ospf_ls_ack (iph
, ospfh
, ibuf
, oi
, length
);
2525 zlog (NULL
, LOG_WARNING
,
2526 "interface %s: OSPF packet header type %d is illegal",
2527 IF_NAME (oi
), ospfh
->type
);
2534 /* Make OSPF header. */
2536 ospf_make_header (int type
, struct ospf_interface
*oi
, struct stream
*s
)
2538 struct ospf_header
*ospfh
;
2540 ospfh
= (struct ospf_header
*) STREAM_DATA (s
);
2542 ospfh
->version
= (u_char
) OSPF_VERSION
;
2543 ospfh
->type
= (u_char
) type
;
2545 ospfh
->router_id
= oi
->ospf
->router_id
;
2547 ospfh
->checksum
= 0;
2548 ospfh
->area_id
= oi
->area
->area_id
;
2549 ospfh
->auth_type
= htons (ospf_auth_type (oi
));
2551 memset (ospfh
->u
.auth_data
, 0, OSPF_AUTH_SIMPLE_SIZE
);
2553 stream_forward_endp (s
, OSPF_HEADER_SIZE
);
2556 /* Make Authentication Data. */
2558 ospf_make_auth (struct ospf_interface
*oi
, struct ospf_header
*ospfh
)
2560 struct crypt_key
*ck
;
2562 switch (ospf_auth_type (oi
))
2564 case OSPF_AUTH_NULL
:
2565 /* memset (ospfh->u.auth_data, 0, sizeof (ospfh->u.auth_data)); */
2567 case OSPF_AUTH_SIMPLE
:
2568 memcpy (ospfh
->u
.auth_data
, OSPF_IF_PARAM (oi
, auth_simple
),
2569 OSPF_AUTH_SIMPLE_SIZE
);
2571 case OSPF_AUTH_CRYPTOGRAPHIC
:
2572 /* If key is not set, then set 0. */
2573 if (list_isempty (OSPF_IF_PARAM (oi
, auth_crypt
)))
2575 ospfh
->u
.crypt
.zero
= 0;
2576 ospfh
->u
.crypt
.key_id
= 0;
2577 ospfh
->u
.crypt
.auth_data_len
= OSPF_AUTH_MD5_SIZE
;
2581 ck
= listgetdata (listtail(OSPF_IF_PARAM (oi
, auth_crypt
)));
2582 ospfh
->u
.crypt
.zero
= 0;
2583 ospfh
->u
.crypt
.key_id
= ck
->key_id
;
2584 ospfh
->u
.crypt
.auth_data_len
= OSPF_AUTH_MD5_SIZE
;
2586 /* note: the seq is done in ospf_make_md5_digest() */
2589 /* memset (ospfh->u.auth_data, 0, sizeof (ospfh->u.auth_data)); */
2596 /* Fill rest of OSPF header. */
2598 ospf_fill_header (struct ospf_interface
*oi
,
2599 struct stream
*s
, u_int16_t length
)
2601 struct ospf_header
*ospfh
;
2603 ospfh
= (struct ospf_header
*) STREAM_DATA (s
);
2606 ospfh
->length
= htons (length
);
2608 /* Calculate checksum. */
2609 if (ntohs (ospfh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
2610 ospfh
->checksum
= in_cksum (ospfh
, length
);
2612 ospfh
->checksum
= 0;
2614 /* Add Authentication Data. */
2615 ospf_make_auth (oi
, ospfh
);
2619 ospf_make_hello (struct ospf_interface
*oi
, struct stream
*s
)
2621 struct ospf_neighbor
*nbr
;
2622 struct route_node
*rn
;
2623 u_int16_t length
= OSPF_HELLO_MIN_SIZE
;
2624 struct in_addr mask
;
2628 /* Set netmask of interface. */
2629 if (oi
->type
!= OSPF_IFTYPE_POINTOPOINT
&&
2630 oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
2631 masklen2ip (oi
->address
->prefixlen
, &mask
);
2633 memset ((char *) &mask
, 0, sizeof (struct in_addr
));
2634 stream_put_ipv4 (s
, mask
.s_addr
);
2636 /* Set Hello Interval. */
2637 if (OSPF_IF_PARAM (oi
, fast_hello
) == 0)
2638 stream_putw (s
, OSPF_IF_PARAM (oi
, v_hello
));
2640 stream_putw (s
, 0); /* hello-interval of 0 for fast-hellos */
2642 if (IS_DEBUG_OSPF_EVENT
)
2643 zlog_debug ("make_hello: options: %x, int: %s",
2644 OPTIONS(oi
), IF_NAME (oi
));
2647 stream_putc (s
, OPTIONS (oi
));
2649 /* Set Router Priority. */
2650 stream_putc (s
, PRIORITY (oi
));
2652 /* Set Router Dead Interval. */
2653 stream_putl (s
, OSPF_IF_PARAM (oi
, v_wait
));
2655 /* Set Designated Router. */
2656 stream_put_ipv4 (s
, DR (oi
).s_addr
);
2658 p
= stream_get_endp (s
);
2660 /* Set Backup Designated Router. */
2661 stream_put_ipv4 (s
, BDR (oi
).s_addr
);
2663 /* Add neighbor seen. */
2664 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
2665 if ((nbr
= rn
->info
))
2666 if (nbr
->router_id
.s_addr
!= 0) /* Ignore 0.0.0.0 node. */
2667 if (nbr
->state
!= NSM_Attempt
) /* Ignore Down neighbor. */
2668 if (nbr
->state
!= NSM_Down
) /* This is myself for DR election. */
2669 if (!IPV4_ADDR_SAME (&nbr
->router_id
, &oi
->ospf
->router_id
))
2671 /* Check neighbor is sane? */
2672 if (nbr
->d_router
.s_addr
!= 0
2673 && IPV4_ADDR_SAME (&nbr
->d_router
, &oi
->address
->u
.prefix4
)
2674 && IPV4_ADDR_SAME (&nbr
->bd_router
, &oi
->address
->u
.prefix4
))
2677 stream_put_ipv4 (s
, nbr
->router_id
.s_addr
);
2681 /* Let neighbor generate BackupSeen. */
2683 stream_putl_at (s
, p
, 0); /* ipv4 address, normally */
2689 ospf_make_db_desc (struct ospf_interface
*oi
, struct ospf_neighbor
*nbr
,
2692 struct ospf_lsa
*lsa
;
2693 u_int16_t length
= OSPF_DB_DESC_MIN_SIZE
;
2697 struct ospf_lsdb
*lsdb
;
2699 /* Set Interface MTU. */
2700 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
2703 stream_putw (s
, oi
->ifp
->mtu
);
2706 options
= OPTIONS (oi
);
2707 #ifdef HAVE_OPAQUE_LSA
2708 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
2710 if (IS_SET_DD_I (nbr
->dd_flags
)
2711 || CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
2713 * Set O-bit in the outgoing DD packet for capablity negotiation,
2714 * if one of following case is applicable.
2716 * 1) WaitTimer expiration event triggered the neighbor state to
2717 * change to Exstart, but no (valid) DD packet has received
2718 * from the neighbor yet.
2720 * 2) At least one DD packet with O-bit on has received from the
2723 SET_FLAG (options
, OSPF_OPTION_O
);
2725 #endif /* HAVE_OPAQUE_LSA */
2726 stream_putc (s
, options
);
2729 pp
= stream_get_endp (s
);
2730 stream_putc (s
, nbr
->dd_flags
);
2732 /* Set DD Sequence Number. */
2733 stream_putl (s
, nbr
->dd_seqnum
);
2735 /* shortcut unneeded walk of (empty) summary LSDBs */
2736 if (ospf_db_summary_isempty (nbr
))
2739 /* Describe LSA Header from Database Summary List. */
2740 lsdb
= &nbr
->db_sum
;
2742 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
2744 struct route_table
*table
= lsdb
->type
[i
].db
;
2745 struct route_node
*rn
;
2747 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2748 if ((lsa
= rn
->info
) != NULL
)
2750 #ifdef HAVE_OPAQUE_LSA
2751 if (IS_OPAQUE_LSA (lsa
->data
->type
)
2752 && (! CHECK_FLAG (options
, OSPF_OPTION_O
)))
2754 /* Suppress advertising opaque-informations. */
2755 /* Remove LSA from DB summary list. */
2756 ospf_lsdb_delete (lsdb
, lsa
);
2759 #endif /* HAVE_OPAQUE_LSA */
2761 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_DISCARD
))
2763 struct lsa_header
*lsah
;
2766 /* DD packet overflows interface MTU. */
2767 if (length
+ OSPF_LSA_HEADER_SIZE
> ospf_packet_max (oi
))
2770 /* Keep pointer to LS age. */
2771 lsah
= (struct lsa_header
*) (STREAM_DATA (s
) +
2772 stream_get_endp (s
));
2774 /* Proceed stream pointer. */
2775 stream_put (s
, lsa
->data
, OSPF_LSA_HEADER_SIZE
);
2776 length
+= OSPF_LSA_HEADER_SIZE
;
2779 ls_age
= LS_AGE (lsa
);
2780 lsah
->ls_age
= htons (ls_age
);
2784 /* Remove LSA from DB summary list. */
2785 ospf_lsdb_delete (lsdb
, lsa
);
2789 /* Update 'More' bit */
2790 if (ospf_db_summary_isempty (nbr
))
2793 if (nbr
->state
>= NSM_Exchange
)
2795 UNSET_FLAG (nbr
->dd_flags
, OSPF_DD_FLAG_M
);
2796 /* Rewrite DD flags */
2797 stream_putc_at (s
, pp
, nbr
->dd_flags
);
2801 assert (IS_SET_DD_M(nbr
->dd_flags
));
2808 ospf_make_ls_req_func (struct stream
*s
, u_int16_t
*length
,
2809 unsigned long delta
, struct ospf_neighbor
*nbr
,
2810 struct ospf_lsa
*lsa
)
2812 struct ospf_interface
*oi
;
2816 /* LS Request packet overflows interface MTU. */
2817 if (*length
+ delta
> ospf_packet_max(oi
))
2820 stream_putl (s
, lsa
->data
->type
);
2821 stream_put_ipv4 (s
, lsa
->data
->id
.s_addr
);
2822 stream_put_ipv4 (s
, lsa
->data
->adv_router
.s_addr
);
2824 ospf_lsa_unlock (&nbr
->ls_req_last
);
2825 nbr
->ls_req_last
= ospf_lsa_lock (lsa
);
2832 ospf_make_ls_req (struct ospf_neighbor
*nbr
, struct stream
*s
)
2834 struct ospf_lsa
*lsa
;
2835 u_int16_t length
= OSPF_LS_REQ_MIN_SIZE
;
2836 unsigned long delta
= stream_get_endp(s
)+12;
2837 struct route_table
*table
;
2838 struct route_node
*rn
;
2840 struct ospf_lsdb
*lsdb
;
2842 lsdb
= &nbr
->ls_req
;
2844 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
2846 table
= lsdb
->type
[i
].db
;
2847 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2848 if ((lsa
= (rn
->info
)) != NULL
)
2849 if (ospf_make_ls_req_func (s
, &length
, delta
, nbr
, lsa
) == 0)
2851 route_unlock_node (rn
);
2859 ls_age_increment (struct ospf_lsa
*lsa
, int delay
)
2863 age
= IS_LSA_MAXAGE (lsa
) ? OSPF_LSA_MAXAGE
: LS_AGE (lsa
) + delay
;
2865 return (age
> OSPF_LSA_MAXAGE
? OSPF_LSA_MAXAGE
: age
);
2869 ospf_make_ls_upd (struct ospf_interface
*oi
, struct list
*update
, struct stream
*s
)
2871 struct ospf_lsa
*lsa
;
2872 struct listnode
*node
;
2873 u_int16_t length
= 0;
2874 unsigned int size_noauth
;
2875 unsigned long delta
= stream_get_endp (s
);
2879 if (IS_DEBUG_OSPF_EVENT
)
2880 zlog_debug ("ospf_make_ls_upd: Start");
2882 pp
= stream_get_endp (s
);
2883 stream_forward_endp (s
, OSPF_LS_UPD_MIN_SIZE
);
2884 length
+= OSPF_LS_UPD_MIN_SIZE
;
2886 /* Calculate amount of packet usable for data. */
2887 size_noauth
= stream_get_size(s
) - ospf_packet_authspace(oi
);
2889 while ((node
= listhead (update
)) != NULL
)
2891 struct lsa_header
*lsah
;
2894 if (IS_DEBUG_OSPF_EVENT
)
2895 zlog_debug ("ospf_make_ls_upd: List Iteration");
2897 lsa
= listgetdata (node
);
2902 if (length
+ delta
+ ntohs (lsa
->data
->length
) > size_noauth
)
2905 /* Keep pointer to LS age. */
2906 lsah
= (struct lsa_header
*) (STREAM_DATA (s
) + stream_get_endp (s
));
2908 /* Put LSA to Link State Request. */
2909 stream_put (s
, lsa
->data
, ntohs (lsa
->data
->length
));
2912 /* each hop must increment an lsa_age by transmit_delay
2913 of OSPF interface */
2914 ls_age
= ls_age_increment (lsa
, OSPF_IF_PARAM (oi
, transmit_delay
));
2915 lsah
->ls_age
= htons (ls_age
);
2917 length
+= ntohs (lsa
->data
->length
);
2920 list_delete_node (update
, node
);
2921 ospf_lsa_unlock (&lsa
); /* oi->ls_upd_queue */
2924 /* Now set #LSAs. */
2925 stream_putl_at (s
, pp
, count
);
2927 if (IS_DEBUG_OSPF_EVENT
)
2928 zlog_debug ("ospf_make_ls_upd: Stop");
2933 ospf_make_ls_ack (struct ospf_interface
*oi
, struct list
*ack
, struct stream
*s
)
2935 struct listnode
*node
, *nnode
;
2936 u_int16_t length
= OSPF_LS_ACK_MIN_SIZE
;
2937 unsigned long delta
= stream_get_endp(s
) + 24;
2938 struct ospf_lsa
*lsa
;
2940 for (ALL_LIST_ELEMENTS (ack
, node
, nnode
, lsa
))
2944 if (length
+ delta
> ospf_packet_max (oi
))
2947 stream_put (s
, lsa
->data
, OSPF_LSA_HEADER_SIZE
);
2948 length
+= OSPF_LSA_HEADER_SIZE
;
2950 listnode_delete (ack
, lsa
);
2951 ospf_lsa_unlock (&lsa
); /* oi->ls_ack_direct.ls_ack */
2958 ospf_hello_send_sub (struct ospf_interface
*oi
, struct in_addr
*addr
)
2960 struct ospf_packet
*op
;
2961 u_int16_t length
= OSPF_HEADER_SIZE
;
2963 op
= ospf_packet_new (oi
->ifp
->mtu
);
2965 /* Prepare OSPF common header. */
2966 ospf_make_header (OSPF_MSG_HELLO
, oi
, op
->s
);
2968 /* Prepare OSPF Hello body. */
2969 length
+= ospf_make_hello (oi
, op
->s
);
2971 /* Fill OSPF header. */
2972 ospf_fill_header (oi
, op
->s
, length
);
2974 /* Set packet length. */
2975 op
->length
= length
;
2977 op
->dst
.s_addr
= addr
->s_addr
;
2979 /* Add packet to the interface output queue. */
2980 ospf_packet_add (oi
, op
);
2982 /* Hook thread to write packet. */
2983 OSPF_ISM_WRITE_ON (oi
->ospf
);
2987 ospf_poll_send (struct ospf_nbr_nbma
*nbr_nbma
)
2989 struct ospf_interface
*oi
;
2994 /* If this is passive interface, do not send OSPF Hello. */
2995 if (OSPF_IF_PASSIVE_STATUS (oi
) == OSPF_IF_PASSIVE
)
2998 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
3001 if (nbr_nbma
->nbr
!= NULL
&& nbr_nbma
->nbr
->state
!= NSM_Down
)
3004 if (PRIORITY(oi
) == 0)
3007 if (nbr_nbma
->priority
== 0
3008 && oi
->state
!= ISM_DR
&& oi
->state
!= ISM_Backup
)
3011 ospf_hello_send_sub (oi
, &nbr_nbma
->addr
);
3015 ospf_poll_timer (struct thread
*thread
)
3017 struct ospf_nbr_nbma
*nbr_nbma
;
3019 nbr_nbma
= THREAD_ARG (thread
);
3020 nbr_nbma
->t_poll
= NULL
;
3022 if (IS_DEBUG_OSPF (nsm
, NSM_TIMERS
))
3023 zlog (NULL
, LOG_DEBUG
, "NSM[%s:%s]: Timer (Poll timer expire)",
3024 IF_NAME (nbr_nbma
->oi
), inet_ntoa (nbr_nbma
->addr
));
3026 ospf_poll_send (nbr_nbma
);
3028 if (nbr_nbma
->v_poll
> 0)
3029 OSPF_POLL_TIMER_ON (nbr_nbma
->t_poll
, ospf_poll_timer
,
3037 ospf_hello_reply_timer (struct thread
*thread
)
3039 struct ospf_neighbor
*nbr
;
3041 nbr
= THREAD_ARG (thread
);
3042 nbr
->t_hello_reply
= NULL
;
3046 if (IS_DEBUG_OSPF (nsm
, NSM_TIMERS
))
3047 zlog (NULL
, LOG_DEBUG
, "NSM[%s:%s]: Timer (hello-reply timer expire)",
3048 IF_NAME (nbr
->oi
), inet_ntoa (nbr
->router_id
));
3050 ospf_hello_send_sub (nbr
->oi
, &nbr
->address
.u
.prefix4
);
3055 /* Send OSPF Hello. */
3057 ospf_hello_send (struct ospf_interface
*oi
)
3059 struct ospf_packet
*op
;
3060 u_int16_t length
= OSPF_HEADER_SIZE
;
3062 /* If this is passive interface, do not send OSPF Hello. */
3063 if (OSPF_IF_PASSIVE_STATUS (oi
) == OSPF_IF_PASSIVE
)
3066 op
= ospf_packet_new (oi
->ifp
->mtu
);
3068 /* Prepare OSPF common header. */
3069 ospf_make_header (OSPF_MSG_HELLO
, oi
, op
->s
);
3071 /* Prepare OSPF Hello body. */
3072 length
+= ospf_make_hello (oi
, op
->s
);
3074 /* Fill OSPF header. */
3075 ospf_fill_header (oi
, op
->s
, length
);
3077 /* Set packet length. */
3078 op
->length
= length
;
3080 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3082 struct ospf_neighbor
*nbr
;
3083 struct route_node
*rn
;
3085 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
3086 if ((nbr
= rn
->info
))
3087 if (nbr
!= oi
->nbr_self
)
3088 if (nbr
->state
!= NSM_Down
)
3090 /* RFC 2328 Section 9.5.1
3091 If the router is not eligible to become Designated Router,
3092 it must periodically send Hello Packets to both the
3093 Designated Router and the Backup Designated Router (if they
3095 if (PRIORITY(oi
) == 0 &&
3096 IPV4_ADDR_CMP(&DR(oi
), &nbr
->address
.u
.prefix4
) &&
3097 IPV4_ADDR_CMP(&BDR(oi
), &nbr
->address
.u
.prefix4
))
3100 /* If the router is eligible to become Designated Router, it
3101 must periodically send Hello Packets to all neighbors that
3102 are also eligible. In addition, if the router is itself the
3103 Designated Router or Backup Designated Router, it must also
3104 send periodic Hello Packets to all other neighbors. */
3106 if (nbr
->priority
== 0 && oi
->state
== ISM_DROther
)
3108 /* if oi->state == Waiting, send hello to all neighbors */
3110 struct ospf_packet
*op_dup
;
3112 op_dup
= ospf_packet_dup(op
);
3113 op_dup
->dst
= nbr
->address
.u
.prefix4
;
3115 /* Add packet to the interface output queue. */
3116 ospf_packet_add (oi
, op_dup
);
3118 OSPF_ISM_WRITE_ON (oi
->ospf
);
3122 ospf_packet_free (op
);
3126 /* Decide destination address. */
3127 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3128 op
->dst
.s_addr
= oi
->vl_data
->peer_addr
.s_addr
;
3130 op
->dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3132 /* Add packet to the interface output queue. */
3133 ospf_packet_add (oi
, op
);
3135 /* Hook thread to write packet. */
3136 OSPF_ISM_WRITE_ON (oi
->ospf
);
3140 /* Send OSPF Database Description. */
3142 ospf_db_desc_send (struct ospf_neighbor
*nbr
)
3144 struct ospf_interface
*oi
;
3145 struct ospf_packet
*op
;
3146 u_int16_t length
= OSPF_HEADER_SIZE
;
3149 op
= ospf_packet_new (oi
->ifp
->mtu
);
3151 /* Prepare OSPF common header. */
3152 ospf_make_header (OSPF_MSG_DB_DESC
, oi
, op
->s
);
3154 /* Prepare OSPF Database Description body. */
3155 length
+= ospf_make_db_desc (oi
, nbr
, op
->s
);
3157 /* Fill OSPF header. */
3158 ospf_fill_header (oi
, op
->s
, length
);
3160 /* Set packet length. */
3161 op
->length
= length
;
3163 /* Decide destination address. */
3164 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3165 op
->dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3167 op
->dst
= nbr
->address
.u
.prefix4
;
3169 /* Add packet to the interface output queue. */
3170 ospf_packet_add (oi
, op
);
3172 /* Hook thread to write packet. */
3173 OSPF_ISM_WRITE_ON (oi
->ospf
);
3175 /* Remove old DD packet, then copy new one and keep in neighbor structure. */
3177 ospf_packet_free (nbr
->last_send
);
3178 nbr
->last_send
= ospf_packet_dup (op
);
3179 quagga_gettime (QUAGGA_CLK_MONOTONIC
, &nbr
->last_send_ts
);
3182 /* Re-send Database Description. */
3184 ospf_db_desc_resend (struct ospf_neighbor
*nbr
)
3186 struct ospf_interface
*oi
;
3190 /* Add packet to the interface output queue. */
3191 ospf_packet_add (oi
, ospf_packet_dup (nbr
->last_send
));
3193 /* Hook thread to write packet. */
3194 OSPF_ISM_WRITE_ON (oi
->ospf
);
3197 /* Send Link State Request. */
3199 ospf_ls_req_send (struct ospf_neighbor
*nbr
)
3201 struct ospf_interface
*oi
;
3202 struct ospf_packet
*op
;
3203 u_int16_t length
= OSPF_HEADER_SIZE
;
3206 op
= ospf_packet_new (oi
->ifp
->mtu
);
3208 /* Prepare OSPF common header. */
3209 ospf_make_header (OSPF_MSG_LS_REQ
, oi
, op
->s
);
3211 /* Prepare OSPF Link State Request body. */
3212 length
+= ospf_make_ls_req (nbr
, op
->s
);
3213 if (length
== OSPF_HEADER_SIZE
)
3215 ospf_packet_free (op
);
3219 /* Fill OSPF header. */
3220 ospf_fill_header (oi
, op
->s
, length
);
3222 /* Set packet length. */
3223 op
->length
= length
;
3225 /* Decide destination address. */
3226 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3227 op
->dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3229 op
->dst
= nbr
->address
.u
.prefix4
;
3231 /* Add packet to the interface output queue. */
3232 ospf_packet_add (oi
, op
);
3234 /* Hook thread to write packet. */
3235 OSPF_ISM_WRITE_ON (oi
->ospf
);
3237 /* Add Link State Request Retransmission Timer. */
3238 OSPF_NSM_TIMER_ON (nbr
->t_ls_req
, ospf_ls_req_timer
, nbr
->v_ls_req
);
3241 /* Send Link State Update with an LSA. */
3243 ospf_ls_upd_send_lsa (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
,
3246 struct list
*update
;
3248 update
= list_new ();
3250 listnode_add (update
, lsa
);
3251 ospf_ls_upd_send (nbr
, update
, flag
);
3253 list_delete (update
);
3256 /* Determine size for packet. Must be at least big enough to accomodate next
3257 * LSA on list, which may be bigger than MTU size.
3259 * Return pointer to new ospf_packet
3260 * NULL if we can not allocate, eg because LSA is bigger than imposed limit
3261 * on packet sizes (in which case offending LSA is deleted from update list)
3263 static struct ospf_packet
*
3264 ospf_ls_upd_packet_new (struct list
*update
, struct ospf_interface
*oi
)
3266 struct ospf_lsa
*lsa
;
3267 struct listnode
*ln
;
3269 static char warned
= 0;
3271 lsa
= listgetdata((ln
= listhead (update
)));
3274 if ((OSPF_LS_UPD_MIN_SIZE
+ ntohs (lsa
->data
->length
))
3275 > ospf_packet_max (oi
))
3279 zlog_warn ("ospf_ls_upd_packet_new: oversized LSA encountered!"
3280 "will need to fragment. Not optimal. Try divide up"
3281 " your network with areas. Use 'debug ospf packet send'"
3282 " to see details, or look at 'show ip ospf database ..'");
3286 if (IS_DEBUG_OSPF_PACKET (0, SEND
))
3287 zlog_debug ("ospf_ls_upd_packet_new: oversized LSA id:%s,"
3288 " %d bytes originated by %s, will be fragmented!",
3289 inet_ntoa (lsa
->data
->id
),
3290 ntohs (lsa
->data
->length
),
3291 inet_ntoa (lsa
->data
->adv_router
));
3294 * Allocate just enough to fit this LSA only, to avoid including other
3295 * LSAs in fragmented LSA Updates.
3297 size
= ntohs (lsa
->data
->length
) + (oi
->ifp
->mtu
- ospf_packet_max (oi
))
3298 + OSPF_LS_UPD_MIN_SIZE
;
3301 size
= oi
->ifp
->mtu
;
3303 if (size
> OSPF_MAX_PACKET_SIZE
)
3305 zlog_warn ("ospf_ls_upd_packet_new: oversized LSA id:%s too big,"
3306 " %d bytes, packet size %ld, dropping it completely."
3307 " OSPF routing is broken!",
3308 inet_ntoa (lsa
->data
->id
), ntohs (lsa
->data
->length
),
3310 list_delete_node (update
, ln
);
3314 /* IP header is built up separately by ospf_write(). This means, that we must
3315 * reduce the "affordable" size just calculated by length of an IP header.
3316 * This makes sure, that even if we manage to fill the payload with LSA data
3317 * completely, the final packet (our data plus IP header) still fits into
3318 * outgoing interface MTU. This correction isn't really meaningful for an
3319 * oversized LSA, but for consistency the correction is done for both cases.
3321 * P.S. OSPF_MAX_PACKET_SIZE above already includes IP header size
3323 return ospf_packet_new (size
- sizeof (struct ip
));
3327 ospf_ls_upd_queue_send (struct ospf_interface
*oi
, struct list
*update
,
3328 struct in_addr addr
)
3330 struct ospf_packet
*op
;
3331 u_int16_t length
= OSPF_HEADER_SIZE
;
3333 if (IS_DEBUG_OSPF_EVENT
)
3334 zlog_debug ("listcount = %d, dst %s", listcount (update
), inet_ntoa(addr
));
3336 op
= ospf_ls_upd_packet_new (update
, oi
);
3338 /* Prepare OSPF common header. */
3339 ospf_make_header (OSPF_MSG_LS_UPD
, oi
, op
->s
);
3341 /* Prepare OSPF Link State Update body.
3342 * Includes Type-7 translation.
3344 length
+= ospf_make_ls_upd (oi
, update
, op
->s
);
3346 /* Fill OSPF header. */
3347 ospf_fill_header (oi
, op
->s
, length
);
3349 /* Set packet length. */
3350 op
->length
= length
;
3352 /* Decide destination address. */
3353 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3354 op
->dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3356 op
->dst
.s_addr
= addr
.s_addr
;
3358 /* Add packet to the interface output queue. */
3359 ospf_packet_add (oi
, op
);
3361 /* Hook thread to write packet. */
3362 OSPF_ISM_WRITE_ON (oi
->ospf
);
3366 ospf_ls_upd_send_queue_event (struct thread
*thread
)
3368 struct ospf_interface
*oi
= THREAD_ARG(thread
);
3369 struct route_node
*rn
;
3370 struct route_node
*rnext
;
3371 struct list
*update
;
3374 oi
->t_ls_upd_event
= NULL
;
3376 if (IS_DEBUG_OSPF_EVENT
)
3377 zlog_debug ("ospf_ls_upd_send_queue start");
3379 for (rn
= route_top (oi
->ls_upd_queue
); rn
; rn
= rnext
)
3381 rnext
= route_next (rn
);
3383 if (rn
->info
== NULL
)
3386 update
= (struct list
*)rn
->info
;
3388 ospf_ls_upd_queue_send (oi
, update
, rn
->p
.u
.prefix4
);
3390 /* list might not be empty. */
3391 if (listcount(update
) == 0)
3393 list_delete (rn
->info
);
3395 route_unlock_node (rn
);
3403 if (IS_DEBUG_OSPF_EVENT
)
3404 zlog_debug ("ospf_ls_upd_send_queue: update lists not cleared,"
3405 " %d nodes to try again, raising new event", again
);
3406 oi
->t_ls_upd_event
=
3407 thread_add_event (master
, ospf_ls_upd_send_queue_event
, oi
, 0);
3410 if (IS_DEBUG_OSPF_EVENT
)
3411 zlog_debug ("ospf_ls_upd_send_queue stop");
3417 ospf_ls_upd_send (struct ospf_neighbor
*nbr
, struct list
*update
, int flag
)
3419 struct ospf_interface
*oi
;
3420 struct ospf_lsa
*lsa
;
3421 struct prefix_ipv4 p
;
3422 struct route_node
*rn
;
3423 struct listnode
*node
;
3428 p
.prefixlen
= IPV4_MAX_BITLEN
;
3430 /* Decide destination address. */
3431 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3432 p
.prefix
= oi
->vl_data
->peer_addr
;
3433 else if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3434 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3435 else if (flag
== OSPF_SEND_PACKET_DIRECT
)
3436 p
.prefix
= nbr
->address
.u
.prefix4
;
3437 else if (oi
->state
== ISM_DR
|| oi
->state
== ISM_Backup
)
3438 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3439 else if (oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
)
3440 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3442 p
.prefix
.s_addr
= htonl (OSPF_ALLDROUTERS
);
3444 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3446 if (flag
== OSPF_SEND_PACKET_INDIRECT
)
3447 zlog_warn ("* LS-Update is directly sent on NBMA network.");
3448 if (IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
, &p
.prefix
.s_addr
))
3449 zlog_warn ("* LS-Update is sent to myself.");
3452 rn
= route_node_get (oi
->ls_upd_queue
, (struct prefix
*) &p
);
3454 if (rn
->info
== NULL
)
3455 rn
->info
= list_new ();
3457 for (ALL_LIST_ELEMENTS_RO (update
, node
, lsa
))
3458 listnode_add (rn
->info
, ospf_lsa_lock (lsa
)); /* oi->ls_upd_queue */
3460 if (oi
->t_ls_upd_event
== NULL
)
3461 oi
->t_ls_upd_event
=
3462 thread_add_event (master
, ospf_ls_upd_send_queue_event
, oi
, 0);
3466 ospf_ls_ack_send_list (struct ospf_interface
*oi
, struct list
*ack
,
3469 struct ospf_packet
*op
;
3470 u_int16_t length
= OSPF_HEADER_SIZE
;
3472 op
= ospf_packet_new (oi
->ifp
->mtu
);
3474 /* Prepare OSPF common header. */
3475 ospf_make_header (OSPF_MSG_LS_ACK
, oi
, op
->s
);
3477 /* Prepare OSPF Link State Acknowledgment body. */
3478 length
+= ospf_make_ls_ack (oi
, ack
, op
->s
);
3480 /* Fill OSPF header. */
3481 ospf_fill_header (oi
, op
->s
, length
);
3483 /* Set packet length. */
3484 op
->length
= length
;
3486 /* Set destination IP address. */
3489 /* Add packet to the interface output queue. */
3490 ospf_packet_add (oi
, op
);
3492 /* Hook thread to write packet. */
3493 OSPF_ISM_WRITE_ON (oi
->ospf
);
3497 ospf_ls_ack_send_event (struct thread
*thread
)
3499 struct ospf_interface
*oi
= THREAD_ARG (thread
);
3501 oi
->t_ls_ack_direct
= NULL
;
3503 while (listcount (oi
->ls_ack_direct
.ls_ack
))
3504 ospf_ls_ack_send_list (oi
, oi
->ls_ack_direct
.ls_ack
,
3505 oi
->ls_ack_direct
.dst
);
3511 ospf_ls_ack_send (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
3513 struct ospf_interface
*oi
= nbr
->oi
;
3515 if (listcount (oi
->ls_ack_direct
.ls_ack
) == 0)
3516 oi
->ls_ack_direct
.dst
= nbr
->address
.u
.prefix4
;
3518 listnode_add (oi
->ls_ack_direct
.ls_ack
, ospf_lsa_lock (lsa
));
3520 if (oi
->t_ls_ack_direct
== NULL
)
3521 oi
->t_ls_ack_direct
=
3522 thread_add_event (master
, ospf_ls_ack_send_event
, oi
, 0);
3525 /* Send Link State Acknowledgment delayed. */
3527 ospf_ls_ack_send_delayed (struct ospf_interface
*oi
)
3531 /* Decide destination address. */
3532 /* RFC2328 Section 13.5 On non-broadcast
3533 networks, delayed Link State Acknowledgment packets must be
3534 unicast separately over each adjacency (i.e., neighbor whose
3535 state is >= Exchange). */
3536 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3538 struct ospf_neighbor
*nbr
;
3539 struct route_node
*rn
;
3541 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
3542 if ((nbr
= rn
->info
) != NULL
)
3543 if (nbr
!= oi
->nbr_self
&& nbr
->state
>= NSM_Exchange
)
3544 while (listcount (oi
->ls_ack
))
3545 ospf_ls_ack_send_list (oi
, oi
->ls_ack
, nbr
->address
.u
.prefix4
);
3548 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3549 dst
.s_addr
= oi
->vl_data
->peer_addr
.s_addr
;
3550 else if (oi
->state
== ISM_DR
|| oi
->state
== ISM_Backup
)
3551 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3552 else if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3553 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3554 else if (oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
)
3555 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3557 dst
.s_addr
= htonl (OSPF_ALLDROUTERS
);
3559 while (listcount (oi
->ls_ack
))
3560 ospf_ls_ack_send_list (oi
, oi
->ls_ack
, dst
);