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 along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include "sockunion.h"
39 #include "ospfd/ospfd.h"
40 #include "ospfd/ospf_network.h"
41 #include "ospfd/ospf_interface.h"
42 #include "ospfd/ospf_ism.h"
43 #include "ospfd/ospf_asbr.h"
44 #include "ospfd/ospf_lsa.h"
45 #include "ospfd/ospf_lsdb.h"
46 #include "ospfd/ospf_neighbor.h"
47 #include "ospfd/ospf_nsm.h"
48 #include "ospfd/ospf_packet.h"
49 #include "ospfd/ospf_spf.h"
50 #include "ospfd/ospf_flood.h"
51 #include "ospfd/ospf_dump.h"
54 * OSPF Fragmentation / fragmented writes
56 * ospfd can support writing fragmented packets, for cases where
57 * kernel will not fragment IP_HDRINCL and/or multicast destined
58 * packets (ie TTBOMK all kernels, BSD, SunOS, Linux). However,
59 * SunOS, probably BSD too, clobber the user supplied IP ID and IP
60 * flags fields, hence user-space fragmentation will not work.
61 * Only Linux is known to leave IP header unmolested.
62 * Further, fragmentation really should be done the kernel, which already
63 * supports it, and which avoids nasty IP ID state problems.
65 * Fragmentation of OSPF packets can be required on networks with router
66 * with many many interfaces active in one area, or on networks with links
70 #define WANT_OSPF_WRITE_FRAGMENT
73 /* Packet Type String. */
74 const struct message ospf_packet_type_str
[] =
76 { OSPF_MSG_HELLO
, "Hello" },
77 { OSPF_MSG_DB_DESC
, "Database Description" },
78 { OSPF_MSG_LS_REQ
, "Link State Request" },
79 { OSPF_MSG_LS_UPD
, "Link State Update" },
80 { OSPF_MSG_LS_ACK
, "Link State Acknowledgment" },
84 /* Minimum (besides OSPF_HEADER_SIZE) lengths for OSPF packets of
85 particular types, offset is the "type" field of a packet. */
86 static const u_int16_t ospf_packet_minlen
[] =
90 OSPF_DB_DESC_MIN_SIZE
,
96 /* Minimum (besides OSPF_LSA_HEADER_SIZE) lengths for LSAs of particular
97 types, offset is the "LSA type" field. */
98 static const u_int16_t ospf_lsa_minlen
[] =
101 OSPF_ROUTER_LSA_MIN_SIZE
,
102 OSPF_NETWORK_LSA_MIN_SIZE
,
103 OSPF_SUMMARY_LSA_MIN_SIZE
,
104 OSPF_SUMMARY_LSA_MIN_SIZE
,
105 OSPF_AS_EXTERNAL_LSA_MIN_SIZE
,
107 OSPF_AS_EXTERNAL_LSA_MIN_SIZE
,
114 /* for ospf_check_auth() */
115 static int ospf_check_sum (struct ospf_header
*);
117 /* OSPF authentication checking function */
119 ospf_auth_type (struct ospf_interface
*oi
)
123 if (OSPF_IF_PARAM (oi
, auth_type
) == OSPF_AUTH_NOTSET
)
124 auth_type
= oi
->area
->auth_type
;
126 auth_type
= OSPF_IF_PARAM (oi
, auth_type
);
128 /* Handle case where MD5 key list is not configured aka Cisco */
129 if (auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
&&
130 list_isempty (OSPF_IF_PARAM (oi
, auth_crypt
)))
131 return OSPF_AUTH_NULL
;
138 ospf_packet_new (size_t size
)
140 struct ospf_packet
*new;
142 new = XCALLOC (MTYPE_OSPF_PACKET
, sizeof (struct ospf_packet
));
143 new->s
= stream_new (size
);
149 ospf_packet_free (struct ospf_packet
*op
)
154 XFREE (MTYPE_OSPF_PACKET
, op
);
162 struct ospf_fifo
*new;
164 new = XCALLOC (MTYPE_OSPF_FIFO
, sizeof (struct ospf_fifo
));
168 /* Add new packet to fifo. */
170 ospf_fifo_push (struct ospf_fifo
*fifo
, struct ospf_packet
*op
)
173 fifo
->tail
->next
= op
;
182 /* Add new packet to head of fifo. */
184 ospf_fifo_push_head (struct ospf_fifo
*fifo
, struct ospf_packet
*op
)
186 op
->next
= fifo
->head
;
188 if (fifo
->tail
== NULL
)
196 /* Delete first packet from fifo. */
198 ospf_fifo_pop (struct ospf_fifo
*fifo
)
200 struct ospf_packet
*op
;
206 fifo
->head
= op
->next
;
208 if (fifo
->head
== NULL
)
217 /* Return first fifo entry. */
219 ospf_fifo_head (struct ospf_fifo
*fifo
)
224 /* Flush ospf packet fifo. */
226 ospf_fifo_flush (struct ospf_fifo
*fifo
)
228 struct ospf_packet
*op
;
229 struct ospf_packet
*next
;
231 for (op
= fifo
->head
; op
; op
= next
)
234 ospf_packet_free (op
);
236 fifo
->head
= fifo
->tail
= NULL
;
240 /* Free ospf packet fifo. */
242 ospf_fifo_free (struct ospf_fifo
*fifo
)
244 ospf_fifo_flush (fifo
);
246 XFREE (MTYPE_OSPF_FIFO
, fifo
);
250 ospf_packet_add (struct ospf_interface
*oi
, struct ospf_packet
*op
)
254 zlog_err("ospf_packet_add(interface %s in state %d [%s], packet type %s, "
255 "destination %s) called with NULL obuf, ignoring "
256 "(please report this bug)!\n",
257 IF_NAME(oi
), oi
->state
, lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
258 lookup_msg(ospf_packet_type_str
, stream_getc_from(op
->s
, 1), NULL
),
259 inet_ntoa (op
->dst
));
263 /* Add packet to end of queue. */
264 ospf_fifo_push (oi
->obuf
, op
);
266 /* Debug of packet fifo*/
267 /* ospf_fifo_debug (oi->obuf); */
271 ospf_packet_add_top (struct ospf_interface
*oi
, struct ospf_packet
*op
)
275 zlog_err("ospf_packet_add(interface %s in state %d [%s], packet type %s, "
276 "destination %s) called with NULL obuf, ignoring "
277 "(please report this bug)!\n",
278 IF_NAME(oi
), oi
->state
, lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
279 lookup_msg(ospf_packet_type_str
, stream_getc_from(op
->s
, 1), NULL
),
280 inet_ntoa (op
->dst
));
284 /* Add packet to head of queue. */
285 ospf_fifo_push_head (oi
->obuf
, op
);
287 /* Debug of packet fifo*/
288 /* ospf_fifo_debug (oi->obuf); */
292 ospf_packet_delete (struct ospf_interface
*oi
)
294 struct ospf_packet
*op
;
296 op
= ospf_fifo_pop (oi
->obuf
);
299 ospf_packet_free (op
);
303 ospf_packet_dup (struct ospf_packet
*op
)
305 struct ospf_packet
*new;
307 if (stream_get_endp(op
->s
) != op
->length
)
309 zlog_warn ("ospf_packet_dup stream %lu ospf_packet %u size mismatch",
310 (u_long
)STREAM_SIZE(op
->s
), op
->length
);
312 /* Reserve space for MD5 authentication that may be added later. */
313 new = ospf_packet_new (stream_get_endp(op
->s
) + OSPF_AUTH_MD5_SIZE
);
314 stream_copy (new->s
, op
->s
);
317 new->length
= op
->length
;
324 ospf_packet_authspace (struct ospf_interface
*oi
)
328 if ( ospf_auth_type (oi
) == OSPF_AUTH_CRYPTOGRAPHIC
)
329 auth
= OSPF_AUTH_MD5_SIZE
;
335 ospf_packet_max (struct ospf_interface
*oi
)
339 max
= oi
->ifp
->mtu
- ospf_packet_authspace(oi
);
341 max
-= (OSPF_HEADER_SIZE
+ sizeof (struct ip
));
348 ospf_check_md5_digest (struct ospf_interface
*oi
, struct ospf_header
*ospfh
)
351 unsigned char digest
[OSPF_AUTH_MD5_SIZE
];
352 struct crypt_key
*ck
;
353 struct ospf_neighbor
*nbr
;
354 u_int16_t length
= ntohs (ospfh
->length
);
356 /* Get secret key. */
357 ck
= ospf_crypt_key_lookup (OSPF_IF_PARAM (oi
, auth_crypt
),
358 ospfh
->u
.crypt
.key_id
);
361 zlog_warn ("interface %s: ospf_check_md5 no key %d",
362 IF_NAME (oi
), ospfh
->u
.crypt
.key_id
);
366 /* check crypto seqnum. */
367 nbr
= ospf_nbr_lookup_by_routerid (oi
->nbrs
, &ospfh
->router_id
);
369 if (nbr
&& ntohl(nbr
->crypt_seqnum
) > ntohl(ospfh
->u
.crypt
.crypt_seqnum
))
371 zlog_warn ("interface %s: ospf_check_md5 bad sequence %d (expect %d)",
373 ntohl(ospfh
->u
.crypt
.crypt_seqnum
),
374 ntohl(nbr
->crypt_seqnum
));
378 /* Generate a digest for the ospf packet - their digest + our digest. */
379 memset(&ctx
, 0, sizeof(ctx
));
381 MD5Update(&ctx
, ospfh
, length
);
382 MD5Update(&ctx
, ck
->auth_key
, OSPF_AUTH_MD5_SIZE
);
383 MD5Final(digest
, &ctx
);
385 /* compare the two */
386 if (memcmp ((caddr_t
)ospfh
+ length
, digest
, OSPF_AUTH_MD5_SIZE
))
388 zlog_warn ("interface %s: ospf_check_md5 checksum mismatch",
393 /* save neighbor's crypt_seqnum */
395 nbr
->crypt_seqnum
= ospfh
->u
.crypt
.crypt_seqnum
;
399 /* This function is called from ospf_write(), it will detect the
400 authentication scheme and if it is MD5, it will change the sequence
401 and update the MD5 digest. */
403 ospf_make_md5_digest (struct ospf_interface
*oi
, struct ospf_packet
*op
)
405 struct ospf_header
*ospfh
;
406 unsigned char digest
[OSPF_AUTH_MD5_SIZE
] = {0};
410 struct crypt_key
*ck
;
411 const u_int8_t
*auth_key
;
413 ibuf
= STREAM_DATA (op
->s
);
414 ospfh
= (struct ospf_header
*) ibuf
;
416 if (ntohs (ospfh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
419 /* We do this here so when we dup a packet, we don't have to
420 waste CPU rewriting other headers.
422 Note that quagga_time /deliberately/ is not used here */
423 t
= (time(NULL
) & 0xFFFFFFFF);
424 if (t
> oi
->crypt_seqnum
)
425 oi
->crypt_seqnum
= t
;
429 ospfh
->u
.crypt
.crypt_seqnum
= htonl (oi
->crypt_seqnum
);
431 /* Get MD5 Authentication key from auth_key list. */
432 if (list_isempty (OSPF_IF_PARAM (oi
, auth_crypt
)))
433 auth_key
= (const u_int8_t
*) digest
;
436 ck
= listgetdata (listtail(OSPF_IF_PARAM (oi
, auth_crypt
)));
437 auth_key
= ck
->auth_key
;
440 /* Generate a digest for the entire packet + our secret key. */
441 memset(&ctx
, 0, sizeof(ctx
));
443 MD5Update(&ctx
, ibuf
, ntohs (ospfh
->length
));
444 MD5Update(&ctx
, auth_key
, OSPF_AUTH_MD5_SIZE
);
445 MD5Final(digest
, &ctx
);
447 /* Append md5 digest to the end of the stream. */
448 stream_put (op
->s
, digest
, OSPF_AUTH_MD5_SIZE
);
450 /* We do *NOT* increment the OSPF header length. */
451 op
->length
= ntohs (ospfh
->length
) + OSPF_AUTH_MD5_SIZE
;
453 if (stream_get_endp(op
->s
) != op
->length
)
455 zlog_warn("ospf_make_md5_digest: length mismatch stream %lu ospf_packet %u",
456 (u_long
)stream_get_endp(op
->s
), op
->length
);
458 return OSPF_AUTH_MD5_SIZE
;
463 ospf_ls_req_timer (struct thread
*thread
)
465 struct ospf_neighbor
*nbr
;
467 nbr
= THREAD_ARG (thread
);
468 nbr
->t_ls_req
= NULL
;
470 /* Send Link State Request. */
471 if (ospf_ls_request_count (nbr
))
472 ospf_ls_req_send (nbr
);
474 /* Set Link State Request retransmission timer. */
475 OSPF_NSM_TIMER_ON (nbr
->t_ls_req
, ospf_ls_req_timer
, nbr
->v_ls_req
);
481 ospf_ls_req_event (struct ospf_neighbor
*nbr
)
485 thread_cancel (nbr
->t_ls_req
);
486 nbr
->t_ls_req
= NULL
;
488 nbr
->t_ls_req
= NULL
;
489 thread_add_event(master
, ospf_ls_req_timer
, nbr
, 0, &nbr
->t_ls_req
);
492 /* Cyclic timer function. Fist registered in ospf_nbr_new () in
495 ospf_ls_upd_timer (struct thread
*thread
)
497 struct ospf_neighbor
*nbr
;
499 nbr
= THREAD_ARG (thread
);
500 nbr
->t_ls_upd
= NULL
;
502 /* Send Link State Update. */
503 if (ospf_ls_retransmit_count (nbr
) > 0)
506 struct ospf_lsdb
*lsdb
;
508 int retransmit_interval
;
510 retransmit_interval
= OSPF_IF_PARAM (nbr
->oi
, retransmit_interval
);
512 lsdb
= &nbr
->ls_rxmt
;
513 update
= list_new ();
515 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
517 struct route_table
*table
= lsdb
->type
[i
].db
;
518 struct route_node
*rn
;
520 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
522 struct ospf_lsa
*lsa
;
524 if ((lsa
= rn
->info
) != NULL
)
526 /* Don't retransmit an LSA if we received it within
527 the last RxmtInterval seconds - this is to allow the
528 neighbour a chance to acknowledge the LSA as it may
529 have ben just received before the retransmit timer
530 fired. This is a small tweak to what is in the RFC,
531 but it will cut out out a lot of retransmit traffic
533 if (monotime_since (&lsa
->tv_recv
, NULL
)
534 >= retransmit_interval
* 1000000LL)
535 listnode_add (update
, rn
->info
);
540 if (listcount (update
) > 0)
541 ospf_ls_upd_send (nbr
, update
, OSPF_SEND_PACKET_DIRECT
);
542 list_delete (update
);
545 /* Set LS Update retransmission timer. */
546 OSPF_NSM_TIMER_ON (nbr
->t_ls_upd
, ospf_ls_upd_timer
, nbr
->v_ls_upd
);
552 ospf_ls_ack_timer (struct thread
*thread
)
554 struct ospf_interface
*oi
;
556 oi
= THREAD_ARG (thread
);
559 /* Send Link State Acknowledgment. */
560 if (listcount (oi
->ls_ack
) > 0)
561 ospf_ls_ack_send_delayed (oi
);
563 /* Set LS Ack timer. */
564 OSPF_ISM_TIMER_ON (oi
->t_ls_ack
, ospf_ls_ack_timer
, oi
->v_ls_ack
);
569 #ifdef WANT_OSPF_WRITE_FRAGMENT
571 ospf_write_frags (int fd
, struct ospf_packet
*op
, struct ip
*iph
,
572 struct msghdr
*msg
, unsigned int maxdatasize
,
573 unsigned int mtu
, int flags
, u_char type
)
575 #define OSPF_WRITE_FRAG_SHIFT 3
580 assert ( op
->length
== stream_get_endp(op
->s
) );
581 assert (msg
->msg_iovlen
== 2);
585 * SunOS, BSD and BSD derived kernels likely will clear ip_id, as
586 * well as the IP_MF flag, making this all quite pointless.
588 * However, for a system on which IP_MF is left alone, and ip_id left
589 * alone or else which sets same ip_id for each fragment this might
592 * XXX-TODO: It would be much nicer to have the kernel's use their
593 * existing fragmentation support to do this for us. Bugs/RFEs need to
594 * be raised against the various kernels.
598 iph
->ip_off
|= IP_MF
;
600 /* ip frag offset is expressed in units of 8byte words */
601 offset
= maxdatasize
>> OSPF_WRITE_FRAG_SHIFT
;
603 iovp
= &msg
->msg_iov
[1];
605 while ( (stream_get_endp(op
->s
) - stream_get_getp (op
->s
))
608 /* data length of this frag is to next offset value */
609 iovp
->iov_len
= offset
<< OSPF_WRITE_FRAG_SHIFT
;
610 iph
->ip_len
= iovp
->iov_len
+ sizeof (struct ip
);
611 assert (iph
->ip_len
<= mtu
);
613 sockopt_iphdrincl_swab_htosys (iph
);
615 ret
= sendmsg (fd
, msg
, flags
);
617 sockopt_iphdrincl_swab_systoh (iph
);
620 zlog_warn ("*** ospf_write_frags: sendmsg failed to %s,"
621 " id %d, off %d, len %d, mtu %u failed with %s",
622 inet_ntoa (iph
->ip_dst
),
627 safe_strerror (errno
));
629 if (IS_DEBUG_OSPF_PACKET (type
- 1, SEND
))
631 zlog_debug ("ospf_write_frags: sent id %d, off %d, len %d to %s\n",
632 iph
->ip_id
, iph
->ip_off
, iph
->ip_len
,
633 inet_ntoa (iph
->ip_dst
));
634 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
636 zlog_debug ("-----------------IP Header Dump----------------------");
637 ospf_ip_header_dump (iph
);
638 zlog_debug ("-----------------------------------------------------");
642 iph
->ip_off
+= offset
;
643 stream_forward_getp (op
->s
, iovp
->iov_len
);
644 iovp
->iov_base
= STREAM_PNT (op
->s
);
647 /* setup for final fragment */
648 iovp
->iov_len
= stream_get_endp(op
->s
) - stream_get_getp (op
->s
);
649 iph
->ip_len
= iovp
->iov_len
+ sizeof (struct ip
);
650 iph
->ip_off
&= (~IP_MF
);
652 #endif /* WANT_OSPF_WRITE_FRAGMENT */
655 ospf_write (struct thread
*thread
)
657 struct ospf
*ospf
= THREAD_ARG (thread
);
658 struct ospf_interface
*oi
;
659 struct ospf_interface
*last_serviced_oi
= NULL
;
660 struct ospf_packet
*op
;
661 struct sockaddr_in sa_dst
;
668 struct listnode
*node
;
669 #ifdef WANT_OSPF_WRITE_FRAGMENT
670 static u_int16_t ipid
= 0;
671 u_int16_t maxdatasize
;
672 #endif /* WANT_OSPF_WRITE_FRAGMENT */
673 #define OSPF_WRITE_IPHL_SHIFT 2
676 ospf
->t_write
= NULL
;
678 node
= listhead (ospf
->oi_write_q
);
680 oi
= listgetdata (node
);
683 #ifdef WANT_OSPF_WRITE_FRAGMENT
684 /* seed ipid static with low order bits of time */
686 ipid
= (time(NULL
) & 0xffff);
687 #endif /* WANT_OSPF_WRITE_FRAGMENT */
689 while ((pkt_count
< ospf
->write_oi_count
) && oi
&& (last_serviced_oi
!= oi
))
691 /* If there is only packet in the queue, the oi is removed from
692 write-q, so fix up the last interface that was serviced */
693 if (last_serviced_oi
== NULL
) {
694 last_serviced_oi
= oi
;
697 #ifdef WANT_OSPF_WRITE_FRAGMENT
698 /* convenience - max OSPF data per packet */
699 maxdatasize
= oi
->ifp
->mtu
- sizeof (struct ip
);
700 #endif /* WANT_OSPF_WRITE_FRAGMENT */
701 /* Get one packet from queue. */
702 op
= ospf_fifo_head (oi
->obuf
);
704 assert (op
->length
>= OSPF_HEADER_SIZE
);
706 if (op
->dst
.s_addr
== htonl (OSPF_ALLSPFROUTERS
)
707 || op
->dst
.s_addr
== htonl (OSPF_ALLDROUTERS
))
708 ospf_if_ipmulticast (ospf
, oi
->address
, oi
->ifp
->ifindex
);
710 /* Rewrite the md5 signature & update the seq */
711 ospf_make_md5_digest (oi
, op
);
713 /* Retrieve OSPF packet type. */
714 stream_set_getp (op
->s
, 1);
715 type
= stream_getc (op
->s
);
717 /* reset get pointer */
718 stream_set_getp (op
->s
, 0);
720 memset (&iph
, 0, sizeof (struct ip
));
721 memset (&sa_dst
, 0, sizeof (sa_dst
));
723 sa_dst
.sin_family
= AF_INET
;
724 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
725 sa_dst
.sin_len
= sizeof(sa_dst
);
726 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
727 sa_dst
.sin_addr
= op
->dst
;
728 sa_dst
.sin_port
= htons (0);
730 /* Set DONTROUTE flag if dst is unicast. */
731 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
732 if (!IN_MULTICAST (htonl (op
->dst
.s_addr
)))
733 flags
= MSG_DONTROUTE
;
735 iph
.ip_hl
= sizeof (struct ip
) >> OSPF_WRITE_IPHL_SHIFT
;
736 /* it'd be very strange for header to not be 4byte-word aligned but.. */
737 if ( sizeof (struct ip
)
738 > (unsigned int)(iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
) )
739 iph
.ip_hl
++; /* we presume sizeof struct ip cant overflow ip_hl.. */
741 iph
.ip_v
= IPVERSION
;
742 iph
.ip_tos
= IPTOS_PREC_INTERNETCONTROL
;
743 iph
.ip_len
= (iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
) + op
->length
;
745 #if defined(__DragonFly__)
747 * DragonFly's raw socket expects ip_len/ip_off in network byte order.
749 iph
.ip_len
= htons(iph
.ip_len
);
752 #ifdef WANT_OSPF_WRITE_FRAGMENT
753 /* XXX-MT: not thread-safe at all..
754 * XXX: this presumes this is only programme sending OSPF packets
755 * otherwise, no guarantee ipid will be unique
758 #endif /* WANT_OSPF_WRITE_FRAGMENT */
761 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
762 iph
.ip_ttl
= OSPF_VL_IP_TTL
;
764 iph
.ip_ttl
= OSPF_IP_TTL
;
765 iph
.ip_p
= IPPROTO_OSPFIGP
;
767 iph
.ip_src
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
768 iph
.ip_dst
.s_addr
= op
->dst
.s_addr
;
770 memset (&msg
, 0, sizeof (msg
));
771 msg
.msg_name
= (caddr_t
) &sa_dst
;
772 msg
.msg_namelen
= sizeof (sa_dst
);
775 iov
[0].iov_base
= (char*)&iph
;
776 iov
[0].iov_len
= iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
;
777 iov
[1].iov_base
= STREAM_PNT (op
->s
);
778 iov
[1].iov_len
= op
->length
;
780 /* Sadly we can not rely on kernels to fragment packets because of either
781 * IP_HDRINCL and/or multicast destination being set.
783 #ifdef WANT_OSPF_WRITE_FRAGMENT
784 if ( op
->length
> maxdatasize
)
785 ospf_write_frags (ospf
->fd
, op
, &iph
, &msg
, maxdatasize
,
786 oi
->ifp
->mtu
, flags
, type
);
787 #endif /* WANT_OSPF_WRITE_FRAGMENT */
789 /* send final fragment (could be first) */
790 sockopt_iphdrincl_swab_htosys (&iph
);
791 ret
= sendmsg (ospf
->fd
, &msg
, flags
);
792 sockopt_iphdrincl_swab_systoh (&iph
);
793 if (IS_DEBUG_OSPF_EVENT
)
794 zlog_debug ("ospf_write to %s, "
795 "id %d, off %d, len %d, interface %s, mtu %u:",
796 inet_ntoa (iph
.ip_dst
), iph
.ip_id
, iph
.ip_off
, iph
.ip_len
,
797 oi
->ifp
->name
, oi
->ifp
->mtu
);
800 zlog_warn ("*** sendmsg in ospf_write failed to %s, "
801 "id %d, off %d, len %d, interface %s, mtu %u: %s",
802 inet_ntoa (iph
.ip_dst
), iph
.ip_id
, iph
.ip_off
, iph
.ip_len
,
803 oi
->ifp
->name
, oi
->ifp
->mtu
, safe_strerror (errno
));
805 /* Show debug sending packet. */
806 if (IS_DEBUG_OSPF_PACKET (type
- 1, SEND
))
808 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
810 zlog_debug ("-----------------------------------------------------");
811 ospf_ip_header_dump (&iph
);
812 stream_set_getp (op
->s
, 0);
813 ospf_packet_dump (op
->s
);
816 zlog_debug ("%s sent to [%s] via [%s].",
817 lookup_msg(ospf_packet_type_str
, type
, NULL
),
821 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
822 zlog_debug ("-----------------------------------------------------");
825 /* Now delete packet from queue. */
826 ospf_packet_delete (oi
);
828 /* Move this interface to the tail of write_q to
829 serve everyone in a round robin fashion */
830 list_delete_node (ospf
->oi_write_q
, node
);
831 if (ospf_fifo_head (oi
->obuf
) == NULL
)
834 last_serviced_oi
= NULL
;
839 listnode_add (ospf
->oi_write_q
, oi
);
842 /* Setup to service from the head of the queue again */
843 if (!list_isempty (ospf
->oi_write_q
))
845 node
= listhead (ospf
->oi_write_q
);
847 oi
= listgetdata (node
);
852 /* If packets still remain in queue, call write thread. */
853 if (!list_isempty (ospf
->oi_write_q
)) {
854 ospf
->t_write
= NULL
;
855 thread_add_write(master
, ospf_write
, ospf
, ospf
->fd
, &ospf
->t_write
);
861 /* OSPF Hello message read -- RFC2328 Section 10.5. */
863 ospf_hello (struct ip
*iph
, struct ospf_header
*ospfh
,
864 struct stream
* s
, struct ospf_interface
*oi
, int size
)
866 struct ospf_hello
*hello
;
867 struct ospf_neighbor
*nbr
;
871 /* increment statistics. */
874 hello
= (struct ospf_hello
*) STREAM_PNT (s
);
876 /* If Hello is myself, silently discard. */
877 if (IPV4_ADDR_SAME (&ospfh
->router_id
, &oi
->ospf
->router_id
))
879 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
881 zlog_debug ("ospf_header[%s/%s]: selforiginated, "
883 lookup_msg(ospf_packet_type_str
, ospfh
->type
, NULL
),
884 inet_ntoa (iph
->ip_src
));
889 /* get neighbor prefix. */
891 p
.prefixlen
= ip_masklen (hello
->network_mask
);
892 p
.u
.prefix4
= iph
->ip_src
;
894 /* Compare network mask. */
895 /* Checking is ignored for Point-to-Point and Virtual link. */
896 if (oi
->type
!= OSPF_IFTYPE_POINTOPOINT
897 && oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
898 if (oi
->address
->prefixlen
!= p
.prefixlen
)
900 zlog_warn ("Packet %s [Hello:RECV]: NetworkMask mismatch on %s (configured prefix length is %d, but hello packet indicates %d).",
901 inet_ntoa(ospfh
->router_id
), IF_NAME(oi
),
902 (int)oi
->address
->prefixlen
, (int)p
.prefixlen
);
906 /* Compare Router Dead Interval. */
907 if (OSPF_IF_PARAM (oi
, v_wait
) != ntohl (hello
->dead_interval
))
909 zlog_warn ("Packet %s [Hello:RECV]: RouterDeadInterval mismatch "
910 "(expected %u, but received %u).",
911 inet_ntoa(ospfh
->router_id
),
912 OSPF_IF_PARAM(oi
, v_wait
), ntohl(hello
->dead_interval
));
916 /* Compare Hello Interval - ignored if fast-hellos are set. */
917 if (OSPF_IF_PARAM (oi
, fast_hello
) == 0)
919 if (OSPF_IF_PARAM (oi
, v_hello
) != ntohs (hello
->hello_interval
))
921 zlog_warn ("Packet %s [Hello:RECV]: HelloInterval mismatch "
922 "(expected %u, but received %u).",
923 inet_ntoa(ospfh
->router_id
),
924 OSPF_IF_PARAM(oi
, v_hello
), ntohs(hello
->hello_interval
));
929 if (IS_DEBUG_OSPF_EVENT
)
930 zlog_debug ("Packet %s [Hello:RECV]: Options %s",
931 inet_ntoa (ospfh
->router_id
),
932 ospf_options_dump (hello
->options
));
934 /* Compare options. */
935 #define REJECT_IF_TBIT_ON 1 /* XXX */
936 #ifdef REJECT_IF_TBIT_ON
937 if (CHECK_FLAG (hello
->options
, OSPF_OPTION_MT
))
940 * This router does not support non-zero TOS.
941 * Drop this Hello packet not to establish neighbor relationship.
943 zlog_warn ("Packet %s [Hello:RECV]: T-bit on, drop it.",
944 inet_ntoa (ospfh
->router_id
));
947 #endif /* REJECT_IF_TBIT_ON */
949 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
)
950 && CHECK_FLAG (hello
->options
, OSPF_OPTION_O
))
953 * This router does know the correct usage of O-bit
954 * the bit should be set in DD packet only.
956 zlog_warn ("Packet %s [Hello:RECV]: O-bit abuse?",
957 inet_ntoa (ospfh
->router_id
));
958 #ifdef STRICT_OBIT_USAGE_CHECK
959 return; /* Reject this packet. */
960 #else /* STRICT_OBIT_USAGE_CHECK */
961 UNSET_FLAG (hello
->options
, OSPF_OPTION_O
); /* Ignore O-bit. */
962 #endif /* STRICT_OBIT_USAGE_CHECK */
965 /* new for NSSA is to ensure that NP is on and E is off */
967 if (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
969 if (! (CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_NP
)
970 && CHECK_FLAG (hello
->options
, OSPF_OPTION_NP
)
971 && ! CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_E
)
972 && ! CHECK_FLAG (hello
->options
, OSPF_OPTION_E
)))
974 zlog_warn ("NSSA-Packet-%s[Hello:RECV]: my options: %x, his options %x", inet_ntoa (ospfh
->router_id
), OPTIONS (oi
), hello
->options
);
977 if (IS_DEBUG_OSPF_NSSA
)
978 zlog_debug ("NSSA-Hello:RECV:Packet from %s:", inet_ntoa(ospfh
->router_id
));
981 /* The setting of the E-bit found in the Hello Packet's Options
982 field must match this area's ExternalRoutingCapability A
983 mismatch causes processing to stop and the packet to be
984 dropped. The setting of the rest of the bits in the Hello
985 Packet's Options field should be ignored. */
986 if (CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_E
) !=
987 CHECK_FLAG (hello
->options
, OSPF_OPTION_E
))
989 zlog_warn ("Packet %s [Hello:RECV]: my options: %x, his options %x",
990 inet_ntoa(ospfh
->router_id
), OPTIONS (oi
), hello
->options
);
994 /* get neighbour struct */
995 nbr
= ospf_nbr_get (oi
, ospfh
, iph
, &p
);
997 /* neighbour must be valid, ospf_nbr_get creates if none existed */
1000 old_state
= nbr
->state
;
1002 /* Add event to thread. */
1003 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_PacketReceived
);
1005 /* RFC2328 Section 9.5.1
1006 If the router is not eligible to become Designated Router,
1007 (snip) It must also send an Hello Packet in reply to an
1008 Hello Packet received from any eligible neighbor (other than
1009 the current Designated Router and Backup Designated Router). */
1010 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1011 if (PRIORITY(oi
) == 0 && hello
->priority
> 0
1012 && IPV4_ADDR_CMP(&DR(oi
), &iph
->ip_src
)
1013 && IPV4_ADDR_CMP(&BDR(oi
), &iph
->ip_src
))
1014 OSPF_NSM_TIMER_ON (nbr
->t_hello_reply
, ospf_hello_reply_timer
,
1015 OSPF_HELLO_REPLY_DELAY
);
1017 /* on NBMA network type, it happens to receive bidirectional Hello packet
1018 without advance 1-Way Received event.
1019 To avoid incorrect DR-seletion, raise 1-Way Received event.*/
1020 if (oi
->type
== OSPF_IFTYPE_NBMA
&&
1021 (old_state
== NSM_Down
|| old_state
== NSM_Attempt
))
1023 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_OneWayReceived
);
1024 nbr
->priority
= hello
->priority
;
1025 nbr
->d_router
= hello
->d_router
;
1026 nbr
->bd_router
= hello
->bd_router
;
1030 if (ospf_nbr_bidirectional (&oi
->ospf
->router_id
, hello
->neighbors
,
1031 size
- OSPF_HELLO_MIN_SIZE
))
1033 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_TwoWayReceived
);
1034 nbr
->options
|= hello
->options
;
1038 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_OneWayReceived
);
1039 /* Set neighbor information. */
1040 nbr
->priority
= hello
->priority
;
1041 nbr
->d_router
= hello
->d_router
;
1042 nbr
->bd_router
= hello
->bd_router
;
1046 /* If neighbor itself declares DR and no BDR exists,
1047 cause event BackupSeen */
1048 if (IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->d_router
))
1049 if (hello
->bd_router
.s_addr
== 0 && oi
->state
== ISM_Waiting
)
1050 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_BackupSeen
);
1052 /* neighbor itself declares BDR. */
1053 if (oi
->state
== ISM_Waiting
&&
1054 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->bd_router
))
1055 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_BackupSeen
);
1057 /* had not previously. */
1058 if ((IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->d_router
) &&
1059 IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &nbr
->d_router
)) ||
1060 (IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &hello
->d_router
) &&
1061 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &nbr
->d_router
)))
1062 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
1064 /* had not previously. */
1065 if ((IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->bd_router
) &&
1066 IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &nbr
->bd_router
)) ||
1067 (IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &hello
->bd_router
) &&
1068 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &nbr
->bd_router
)))
1069 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
1071 /* Neighbor priority check. */
1072 if (nbr
->priority
>= 0 && nbr
->priority
!= hello
->priority
)
1073 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
1075 /* Set neighbor information. */
1076 nbr
->priority
= hello
->priority
;
1077 nbr
->d_router
= hello
->d_router
;
1078 nbr
->bd_router
= hello
->bd_router
;
1081 /* Save DD flags/options/Seqnum received. */
1083 ospf_db_desc_save_current (struct ospf_neighbor
*nbr
,
1084 struct ospf_db_desc
*dd
)
1086 nbr
->last_recv
.flags
= dd
->flags
;
1087 nbr
->last_recv
.options
= dd
->options
;
1088 nbr
->last_recv
.dd_seqnum
= ntohl (dd
->dd_seqnum
);
1091 /* Process rest of DD packet. */
1093 ospf_db_desc_proc (struct stream
*s
, struct ospf_interface
*oi
,
1094 struct ospf_neighbor
*nbr
, struct ospf_db_desc
*dd
,
1097 struct ospf_lsa
*new, *find
;
1098 struct lsa_header
*lsah
;
1100 stream_forward_getp (s
, OSPF_DB_DESC_MIN_SIZE
);
1101 for (size
-= OSPF_DB_DESC_MIN_SIZE
;
1102 size
>= OSPF_LSA_HEADER_SIZE
; size
-= OSPF_LSA_HEADER_SIZE
)
1104 lsah
= (struct lsa_header
*) STREAM_PNT (s
);
1105 stream_forward_getp (s
, OSPF_LSA_HEADER_SIZE
);
1107 /* Unknown LS type. */
1108 if (lsah
->type
< OSPF_MIN_LSA
|| lsah
->type
>= OSPF_MAX_LSA
)
1110 zlog_warn ("Packet [DD:RECV]: Unknown LS type %d.", lsah
->type
);
1111 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1115 if (IS_OPAQUE_LSA (lsah
->type
)
1116 && ! CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
1118 zlog_warn ("LSA[Type%d:%s]: Opaque capability mismatch?", lsah
->type
, inet_ntoa (lsah
->id
));
1119 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1125 case OSPF_AS_EXTERNAL_LSA
:
1126 case OSPF_OPAQUE_AS_LSA
:
1127 /* Check for stub area. Reject if AS-External from stub but
1128 allow if from NSSA. */
1129 if (oi
->area
->external_routing
== OSPF_AREA_STUB
)
1131 zlog_warn ("Packet [DD:RECV]: LSA[Type%d:%s] from %s area.",
1132 lsah
->type
, inet_ntoa (lsah
->id
),
1133 (oi
->area
->external_routing
== OSPF_AREA_STUB
) ?\
1135 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1143 /* Create LS-request object. */
1144 new = ospf_ls_request_new (lsah
);
1146 /* Lookup received LSA, then add LS request list. */
1147 find
= ospf_lsa_lookup_by_header (oi
->area
, lsah
);
1149 /* ospf_lsa_more_recent is fine with NULL pointers */
1150 switch (ospf_lsa_more_recent (find
, new))
1153 /* Neighbour has a more recent LSA, we must request it */
1154 ospf_ls_request_add (nbr
, new);
1156 /* If we have a copy of this LSA, it's either less recent
1157 * and we're requesting it from neighbour (the case above), or
1158 * it's as recent and we both have same copy (this case).
1160 * In neither of these two cases is there any point in
1161 * describing our copy of the LSA to the neighbour in a
1162 * DB-Summary packet, if we're still intending to do so.
1164 * See: draft-ogier-ospf-dbex-opt-00.txt, describing the
1165 * backward compatible optimisation to OSPF DB Exchange /
1166 * DB Description process implemented here.
1169 ospf_lsdb_delete (&nbr
->db_sum
, find
);
1170 ospf_lsa_discard (new);
1173 /* We have the more recent copy, nothing specific to do:
1174 * - no need to request neighbours stale copy
1175 * - must leave DB summary list copy alone
1177 if (IS_DEBUG_OSPF_EVENT
)
1178 zlog_debug ("Packet [DD:RECV]: LSA received Type %d, "
1179 "ID %s is not recent.", lsah
->type
, inet_ntoa (lsah
->id
));
1180 ospf_lsa_discard (new);
1185 if (IS_SET_DD_MS (nbr
->dd_flags
))
1189 /* Both sides have no More, then we're done with Exchange */
1190 if (!IS_SET_DD_M (dd
->flags
) && !IS_SET_DD_M (nbr
->dd_flags
))
1191 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_ExchangeDone
);
1193 ospf_db_desc_send (nbr
);
1198 nbr
->dd_seqnum
= ntohl (dd
->dd_seqnum
);
1200 /* Send DD packet in reply.
1202 * Must be done to acknowledge the Master's DD, regardless of
1203 * whether we have more LSAs ourselves to describe.
1205 * This function will clear the 'More' bit, if after this DD
1206 * we have no more LSAs to describe to the master..
1208 ospf_db_desc_send (nbr
);
1210 /* Slave can raise ExchangeDone now, if master is also done */
1211 if (!IS_SET_DD_M (dd
->flags
) && !IS_SET_DD_M (nbr
->dd_flags
))
1212 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_ExchangeDone
);
1215 /* Save received neighbor values from DD. */
1216 ospf_db_desc_save_current (nbr
, dd
);
1219 ospf_ls_req_send (nbr
);
1223 ospf_db_desc_is_dup (struct ospf_db_desc
*dd
, struct ospf_neighbor
*nbr
)
1225 /* Is DD duplicated? */
1226 if (dd
->options
== nbr
->last_recv
.options
&&
1227 dd
->flags
== nbr
->last_recv
.flags
&&
1228 dd
->dd_seqnum
== htonl (nbr
->last_recv
.dd_seqnum
))
1234 /* OSPF Database Description message read -- RFC2328 Section 10.6. */
1236 ospf_db_desc (struct ip
*iph
, struct ospf_header
*ospfh
,
1237 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1239 struct ospf_db_desc
*dd
;
1240 struct ospf_neighbor
*nbr
;
1242 /* Increment statistics. */
1245 dd
= (struct ospf_db_desc
*) STREAM_PNT (s
);
1247 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1250 zlog_warn ("Packet[DD]: Unknown Neighbor %s",
1251 inet_ntoa (ospfh
->router_id
));
1256 if ((OSPF_IF_PARAM (oi
, mtu_ignore
) == 0) &&
1257 (ntohs (dd
->mtu
) > oi
->ifp
->mtu
))
1259 zlog_warn ("Packet[DD]: Neighbor %s MTU %u is larger than [%s]'s MTU %u",
1260 inet_ntoa (nbr
->router_id
), ntohs (dd
->mtu
),
1261 IF_NAME (oi
), oi
->ifp
->mtu
);
1266 * XXX HACK by Hasso Tepper. Setting N/P bit in NSSA area DD packets is not
1267 * required. In fact at least JunOS sends DD packets with P bit clear.
1268 * Until proper solution is developped, this hack should help.
1270 * Update: According to the RFCs, N bit is specified /only/ for Hello
1271 * options, unfortunately its use in DD options is not specified. Hence some
1272 * implementations follow E-bit semantics and set it in DD options, and some
1273 * treat it as unspecified and hence follow the directive "default for
1274 * options is clear", ie unset.
1276 * Reset the flag, as ospfd follows E-bit semantics.
1278 if ( (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
1279 && (CHECK_FLAG (nbr
->options
, OSPF_OPTION_NP
))
1280 && (!CHECK_FLAG (dd
->options
, OSPF_OPTION_NP
)) )
1282 if (IS_DEBUG_OSPF_EVENT
)
1283 zlog_debug ("Packet[DD]: Neighbour %s: Has NSSA capability, sends with N bit clear in DD options",
1284 inet_ntoa (nbr
->router_id
) );
1285 SET_FLAG (dd
->options
, OSPF_OPTION_NP
);
1288 #ifdef REJECT_IF_TBIT_ON
1289 if (CHECK_FLAG (dd
->options
, OSPF_OPTION_MT
))
1292 * In Hello protocol, optional capability must have checked
1293 * to prevent this T-bit enabled router be my neighbor.
1295 zlog_warn ("Packet[DD]: Neighbor %s: T-bit on?", inet_ntoa (nbr
->router_id
));
1298 #endif /* REJECT_IF_TBIT_ON */
1300 if (CHECK_FLAG (dd
->options
, OSPF_OPTION_O
)
1301 && !CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
1304 * This node is not configured to handle O-bit, for now.
1305 * Clear it to ignore unsupported capability proposed by neighbor.
1307 UNSET_FLAG (dd
->options
, OSPF_OPTION_O
);
1310 /* Add event to thread. */
1311 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_PacketReceived
);
1313 /* Process DD packet by neighbor status. */
1319 zlog_warn ("Packet[DD]: Neighbor %s state is %s, packet discarded.",
1320 inet_ntoa(nbr
->router_id
),
1321 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
1324 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_TwoWayReceived
);
1325 /* If the new state is ExStart, the processing of the current
1326 packet should then continue in this new state by falling
1327 through to case ExStart below. */
1328 if (nbr
->state
!= NSM_ExStart
)
1332 if ((IS_SET_DD_ALL (dd
->flags
) == OSPF_DD_FLAG_ALL
) &&
1333 (size
== OSPF_DB_DESC_MIN_SIZE
))
1335 if (IPV4_ADDR_CMP (&nbr
->router_id
, &oi
->ospf
->router_id
) > 0)
1337 /* We're Slave---obey */
1338 zlog_info ("Packet[DD]: Neighbor %s Negotiation done (Slave).",
1339 inet_ntoa(nbr
->router_id
));
1340 nbr
->dd_seqnum
= ntohl (dd
->dd_seqnum
);
1343 UNSET_FLAG (nbr
->dd_flags
, (OSPF_DD_FLAG_MS
|OSPF_DD_FLAG_I
));
1347 /* We're Master, ignore the initial DBD from Slave */
1348 zlog_info ("Packet[DD]: Neighbor %s: Initial DBD from Slave, "
1349 "ignoring.", inet_ntoa(nbr
->router_id
));
1353 /* Ack from the Slave */
1354 else if (!IS_SET_DD_MS (dd
->flags
) && !IS_SET_DD_I (dd
->flags
) &&
1355 ntohl (dd
->dd_seqnum
) == nbr
->dd_seqnum
&&
1356 IPV4_ADDR_CMP (&nbr
->router_id
, &oi
->ospf
->router_id
) < 0)
1358 zlog_info ("Packet[DD]: Neighbor %s Negotiation done (Master).",
1359 inet_ntoa(nbr
->router_id
));
1360 /* Reset I, leaving MS */
1361 UNSET_FLAG (nbr
->dd_flags
, OSPF_DD_FLAG_I
);
1365 zlog_warn ("Packet[DD]: Neighbor %s Negotiation fails.",
1366 inet_ntoa(nbr
->router_id
));
1370 /* This is where the real Options are saved */
1371 nbr
->options
= dd
->options
;
1373 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
1375 if (IS_DEBUG_OSPF_EVENT
)
1376 zlog_debug ("Neighbor[%s] is %sOpaque-capable.",
1377 inet_ntoa (nbr
->router_id
),
1378 CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
) ? "" : "NOT ");
1380 if (! CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
)
1381 && IPV4_ADDR_SAME (&DR (oi
), &nbr
->address
.u
.prefix4
))
1383 zlog_warn ("DR-neighbor[%s] is NOT opaque-capable; "
1384 "Opaque-LSAs cannot be reliably advertised "
1386 inet_ntoa (nbr
->router_id
));
1387 /* This situation is undesirable, but not a real error. */
1391 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_NegotiationDone
);
1393 /* continue processing rest of packet. */
1394 ospf_db_desc_proc (s
, oi
, nbr
, dd
, size
);
1397 if (ospf_db_desc_is_dup (dd
, nbr
))
1399 if (IS_SET_DD_MS (nbr
->dd_flags
))
1400 /* Master: discard duplicated DD packet. */
1401 zlog_info ("Packet[DD] (Master): Neighbor %s packet duplicated.",
1402 inet_ntoa (nbr
->router_id
));
1404 /* Slave: cause to retransmit the last Database Description. */
1406 zlog_info ("Packet[DD] [Slave]: Neighbor %s packet duplicated.",
1407 inet_ntoa (nbr
->router_id
));
1408 ospf_db_desc_resend (nbr
);
1413 /* Otherwise DD packet should be checked. */
1414 /* Check Master/Slave bit mismatch */
1415 if (IS_SET_DD_MS (dd
->flags
) != IS_SET_DD_MS (nbr
->last_recv
.flags
))
1417 zlog_warn ("Packet[DD]: Neighbor %s MS-bit mismatch.",
1418 inet_ntoa(nbr
->router_id
));
1419 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1420 if (IS_DEBUG_OSPF_EVENT
)
1421 zlog_debug ("Packet[DD]: dd->flags=%d, nbr->dd_flags=%d",
1422 dd
->flags
, nbr
->dd_flags
);
1426 /* Check initialize bit is set. */
1427 if (IS_SET_DD_I (dd
->flags
))
1429 zlog_info ("Packet[DD]: Neighbor %s I-bit set.",
1430 inet_ntoa(nbr
->router_id
));
1431 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1435 /* Check DD Options. */
1436 if (dd
->options
!= nbr
->options
)
1438 #ifdef ORIGINAL_CODING
1439 /* Save the new options for debugging */
1440 nbr
->options
= dd
->options
;
1441 #endif /* ORIGINAL_CODING */
1442 zlog_warn ("Packet[DD]: Neighbor %s options mismatch.",
1443 inet_ntoa(nbr
->router_id
));
1444 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1448 /* Check DD sequence number. */
1449 if ((IS_SET_DD_MS (nbr
->dd_flags
) &&
1450 ntohl (dd
->dd_seqnum
) != nbr
->dd_seqnum
) ||
1451 (!IS_SET_DD_MS (nbr
->dd_flags
) &&
1452 ntohl (dd
->dd_seqnum
) != nbr
->dd_seqnum
+ 1))
1454 zlog_warn ("Packet[DD]: Neighbor %s sequence number mismatch.",
1455 inet_ntoa(nbr
->router_id
));
1456 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1460 /* Continue processing rest of packet. */
1461 ospf_db_desc_proc (s
, oi
, nbr
, dd
, size
);
1465 if (ospf_db_desc_is_dup (dd
, nbr
))
1467 if (IS_SET_DD_MS (nbr
->dd_flags
))
1469 /* Master should discard duplicate DD packet. */
1470 zlog_info ("Packet[DD]: Neighbor %s duplicated, "
1471 "packet discarded.",
1472 inet_ntoa(nbr
->router_id
));
1477 if (monotime_since (&nbr
->last_send_ts
, NULL
)
1478 < nbr
->v_inactivity
* 1000000LL)
1480 /* In states Loading and Full the slave must resend
1481 its last Database Description packet in response to
1482 duplicate Database Description packets received
1483 from the master. For this reason the slave must
1484 wait RouterDeadInterval seconds before freeing the
1485 last Database Description packet. Reception of a
1486 Database Description packet from the master after
1487 this interval will generate a SeqNumberMismatch
1488 neighbor event. RFC2328 Section 10.8 */
1489 ospf_db_desc_resend (nbr
);
1495 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1498 zlog_warn ("Packet[DD]: Neighbor %s NSM illegal status %u.",
1499 inet_ntoa(nbr
->router_id
), nbr
->state
);
1504 #define OSPF_LSA_KEY_SIZE 12 /* type(4) + id(4) + ar(4) */
1506 /* OSPF Link State Request Read -- RFC2328 Section 10.7. */
1508 ospf_ls_req (struct ip
*iph
, struct ospf_header
*ospfh
,
1509 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1511 struct ospf_neighbor
*nbr
;
1513 struct in_addr ls_id
;
1514 struct in_addr adv_router
;
1515 struct ospf_lsa
*find
;
1516 struct list
*ls_upd
;
1517 unsigned int length
;
1519 /* Increment statistics. */
1522 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1525 zlog_warn ("Link State Request: Unknown Neighbor %s.",
1526 inet_ntoa (ospfh
->router_id
));
1530 /* Add event to thread. */
1531 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_PacketReceived
);
1533 /* Neighbor State should be Exchange or later. */
1534 if (nbr
->state
!= NSM_Exchange
&&
1535 nbr
->state
!= NSM_Loading
&&
1536 nbr
->state
!= NSM_Full
)
1538 zlog_warn ("Link State Request received from %s: "
1539 "Neighbor state is %s, packet discarded.",
1540 inet_ntoa (ospfh
->router_id
),
1541 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
1545 /* Send Link State Update for ALL requested LSAs. */
1546 ls_upd
= list_new ();
1547 length
= OSPF_HEADER_SIZE
+ OSPF_LS_UPD_MIN_SIZE
;
1549 while (size
>= OSPF_LSA_KEY_SIZE
)
1551 /* Get one slice of Link State Request. */
1552 ls_type
= stream_getl (s
);
1553 ls_id
.s_addr
= stream_get_ipv4 (s
);
1554 adv_router
.s_addr
= stream_get_ipv4 (s
);
1556 /* Verify LSA type. */
1557 if (ls_type
< OSPF_MIN_LSA
|| ls_type
>= OSPF_MAX_LSA
)
1559 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
1560 list_delete (ls_upd
);
1564 /* Search proper LSA in LSDB. */
1565 find
= ospf_lsa_lookup (oi
->area
, ls_type
, ls_id
, adv_router
);
1568 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
1569 list_delete (ls_upd
);
1573 /* Packet overflows MTU size, send immediately. */
1574 if (length
+ ntohs (find
->data
->length
) > ospf_packet_max (oi
))
1576 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1577 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_DIRECT
);
1579 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_INDIRECT
);
1581 /* Only remove list contents. Keep ls_upd. */
1582 list_delete_all_node (ls_upd
);
1584 length
= OSPF_HEADER_SIZE
+ OSPF_LS_UPD_MIN_SIZE
;
1587 /* Append LSA to update list. */
1588 listnode_add (ls_upd
, find
);
1589 length
+= ntohs (find
->data
->length
);
1591 size
-= OSPF_LSA_KEY_SIZE
;
1594 /* Send rest of Link State Update. */
1595 if (listcount (ls_upd
) > 0)
1597 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1598 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_DIRECT
);
1600 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_INDIRECT
);
1602 list_delete (ls_upd
);
1608 /* Get the list of LSAs from Link State Update packet.
1609 And process some validation -- RFC2328 Section 13. (1)-(2). */
1610 static struct list
*
1611 ospf_ls_upd_list_lsa (struct ospf_neighbor
*nbr
, struct stream
*s
,
1612 struct ospf_interface
*oi
, size_t size
)
1614 u_int16_t count
, sum
;
1616 struct lsa_header
*lsah
;
1617 struct ospf_lsa
*lsa
;
1622 count
= stream_getl (s
);
1623 size
-= OSPF_LS_UPD_MIN_SIZE
; /* # LSAs */
1625 for (; size
>= OSPF_LSA_HEADER_SIZE
&& count
> 0;
1626 size
-= length
, stream_forward_getp (s
, length
), count
--)
1628 lsah
= (struct lsa_header
*) STREAM_PNT (s
);
1629 length
= ntohs (lsah
->length
);
1633 zlog_warn ("Link State Update: LSA length exceeds packet size.");
1637 /* Validate the LSA's LS checksum. */
1638 sum
= lsah
->checksum
;
1639 if (! ospf_lsa_checksum_valid (lsah
))
1641 /* (bug #685) more details in a one-line message make it possible
1642 * to identify problem source on the one hand and to have a better
1643 * chance to compress repeated messages in syslog on the other */
1644 zlog_warn ("Link State Update: LSA checksum error %x/%x, ID=%s from: nbr %s, router ID %s, adv router %s",
1645 sum
, lsah
->checksum
, inet_ntoa (lsah
->id
),
1646 inet_ntoa (nbr
->src
), inet_ntoa (nbr
->router_id
),
1647 inet_ntoa (lsah
->adv_router
));
1651 /* Examine the LSA's LS type. */
1652 if (lsah
->type
< OSPF_MIN_LSA
|| lsah
->type
>= OSPF_MAX_LSA
)
1654 zlog_warn ("Link State Update: Unknown LS type %d", lsah
->type
);
1659 * What if the received LSA's age is greater than MaxAge?
1660 * Treat it as a MaxAge case -- endo.
1662 if (ntohs (lsah
->ls_age
) > OSPF_LSA_MAXAGE
)
1663 lsah
->ls_age
= htons (OSPF_LSA_MAXAGE
);
1665 if (CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
1667 #ifdef STRICT_OBIT_USAGE_CHECK
1668 if ((IS_OPAQUE_LSA(lsah
->type
) &&
1669 ! CHECK_FLAG (lsah
->options
, OSPF_OPTION_O
))
1670 || (! IS_OPAQUE_LSA(lsah
->type
) &&
1671 CHECK_FLAG (lsah
->options
, OSPF_OPTION_O
)))
1674 * This neighbor must know the exact usage of O-bit;
1675 * the bit will be set in Type-9,10,11 LSAs only.
1677 zlog_warn ("LSA[Type%d:%s]: O-bit abuse?", lsah
->type
, inet_ntoa (lsah
->id
));
1680 #endif /* STRICT_OBIT_USAGE_CHECK */
1682 /* Do not take in AS External Opaque-LSAs if we are a stub. */
1683 if (lsah
->type
== OSPF_OPAQUE_AS_LSA
1684 && nbr
->oi
->area
->external_routing
!= OSPF_AREA_DEFAULT
)
1686 if (IS_DEBUG_OSPF_EVENT
)
1687 zlog_debug ("LSA[Type%d:%s]: We are a stub, don't take this LSA.", lsah
->type
, inet_ntoa (lsah
->id
));
1691 else if (IS_OPAQUE_LSA(lsah
->type
))
1693 zlog_warn ("LSA[Type%d:%s]: Opaque capability mismatch?", lsah
->type
, inet_ntoa (lsah
->id
));
1697 /* Create OSPF LSA instance. */
1698 lsa
= ospf_lsa_new ();
1700 /* We may wish to put some error checking if type NSSA comes in
1701 and area not in NSSA mode */
1704 case OSPF_AS_EXTERNAL_LSA
:
1705 case OSPF_OPAQUE_AS_LSA
:
1708 case OSPF_OPAQUE_LINK_LSA
:
1709 lsa
->oi
= oi
; /* Remember incoming interface for flooding control. */
1712 lsa
->area
= oi
->area
;
1716 lsa
->data
= ospf_lsa_data_new (length
);
1717 memcpy (lsa
->data
, lsah
, length
);
1719 if (IS_DEBUG_OSPF_EVENT
)
1720 zlog_debug("LSA[Type%d:%s]: %p new LSA created with Link State Update",
1721 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), (void *)lsa
);
1722 listnode_add (lsas
, lsa
);
1728 /* Cleanup Update list. */
1730 ospf_upd_list_clean (struct list
*lsas
)
1732 struct listnode
*node
, *nnode
;
1733 struct ospf_lsa
*lsa
;
1735 for (ALL_LIST_ELEMENTS (lsas
, node
, nnode
, lsa
))
1736 ospf_lsa_discard (lsa
);
1741 /* OSPF Link State Update message read -- RFC2328 Section 13. */
1743 ospf_ls_upd (struct ospf
*ospf
, struct ip
*iph
, struct ospf_header
*ospfh
,
1744 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1746 struct ospf_neighbor
*nbr
;
1748 struct listnode
*node
, *nnode
;
1749 struct ospf_lsa
*lsa
= NULL
;
1750 /* unsigned long ls_req_found = 0; */
1752 /* Dis-assemble the stream, update each entry, re-encapsulate for flooding */
1754 /* Increment statistics. */
1757 /* Check neighbor. */
1758 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1761 zlog_warn ("Link State Update: Unknown Neighbor %s on int: %s",
1762 inet_ntoa (ospfh
->router_id
), IF_NAME (oi
));
1766 /* Add event to thread. */
1767 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_PacketReceived
);
1769 /* Check neighbor state. */
1770 if (nbr
->state
< NSM_Exchange
)
1772 if (IS_DEBUG_OSPF (nsm
, NSM_EVENTS
))
1773 zlog_debug ("Link State Update: "
1774 "Neighbor[%s] state %s is less than Exchange",
1775 inet_ntoa (ospfh
->router_id
),
1776 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
1780 /* Get list of LSAs from Link State Update packet. - Also perorms Stages
1781 * 1 (validate LSA checksum) and 2 (check for LSA consistent type)
1784 lsas
= ospf_ls_upd_list_lsa (nbr
, s
, oi
, size
);
1786 #define DISCARD_LSA(L,N) {\
1787 if (IS_DEBUG_OSPF_EVENT) \
1788 zlog_debug ("ospf_lsa_discard() in ospf_ls_upd() point %d: lsa %p" \
1789 " Type-%d", N, (void *)lsa, (int) lsa->data->type); \
1790 ospf_lsa_discard (L); \
1793 /* Process each LSA received in the one packet.
1795 * Numbers in parentheses, e.g. (1), (2), etc., and the corresponding
1796 * text below are from the steps in RFC 2328, Section 13.
1798 for (ALL_LIST_ELEMENTS (lsas
, node
, nnode
, lsa
))
1800 struct ospf_lsa
*ls_ret
, *current
;
1803 if (IS_DEBUG_OSPF_NSSA
)
1805 char buf1
[INET_ADDRSTRLEN
];
1806 char buf2
[INET_ADDRSTRLEN
];
1807 char buf3
[INET_ADDRSTRLEN
];
1809 zlog_debug("LSA Type-%d from %s, ID: %s, ADV: %s",
1811 inet_ntop (AF_INET
, &ospfh
->router_id
,
1812 buf1
, INET_ADDRSTRLEN
),
1813 inet_ntop (AF_INET
, &lsa
->data
->id
,
1814 buf2
, INET_ADDRSTRLEN
),
1815 inet_ntop (AF_INET
, &lsa
->data
->adv_router
,
1816 buf3
, INET_ADDRSTRLEN
));
1819 listnode_delete (lsas
, lsa
); /* We don't need it in list anymore */
1821 /* (1) Validate Checksum - Done above by ospf_ls_upd_list_lsa() */
1823 /* (2) LSA Type - Done above by ospf_ls_upd_list_lsa() */
1825 /* (3) Do not take in AS External LSAs if we are a stub or NSSA. */
1827 /* Do not take in AS NSSA if this neighbor and we are not NSSA */
1829 /* Do take in Type-7's if we are an NSSA */
1831 /* If we are also an ABR, later translate them to a Type-5 packet */
1833 /* Later, an NSSA Re-fresh can Re-fresh Type-7's and an ABR will
1834 translate them to a separate Type-5 packet. */
1836 if (lsa
->data
->type
== OSPF_AS_EXTERNAL_LSA
)
1837 /* Reject from STUB or NSSA */
1838 if (nbr
->oi
->area
->external_routing
!= OSPF_AREA_DEFAULT
)
1840 if (IS_DEBUG_OSPF_NSSA
)
1841 zlog_debug("Incoming External LSA Discarded: We are NSSA/STUB Area");
1842 DISCARD_LSA (lsa
, 1);
1845 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
)
1846 if (nbr
->oi
->area
->external_routing
!= OSPF_AREA_NSSA
)
1848 if (IS_DEBUG_OSPF_NSSA
)
1849 zlog_debug("Incoming NSSA LSA Discarded: Not NSSA Area");
1850 DISCARD_LSA (lsa
,2);
1853 /* VU229804: Router-LSA Adv-ID must be equal to LS-ID */
1854 if (lsa
->data
->type
== OSPF_ROUTER_LSA
)
1855 if (!IPV4_ADDR_SAME(&lsa
->data
->id
, &lsa
->data
->adv_router
))
1857 char buf1
[INET_ADDRSTRLEN
];
1858 char buf2
[INET_ADDRSTRLEN
];
1859 char buf3
[INET_ADDRSTRLEN
];
1861 zlog_err("Incoming Router-LSA from %s with "
1862 "Adv-ID[%s] != LS-ID[%s]",
1863 inet_ntop (AF_INET
, &ospfh
->router_id
,
1864 buf1
, INET_ADDRSTRLEN
),
1865 inet_ntop (AF_INET
, &lsa
->data
->id
,
1866 buf2
, INET_ADDRSTRLEN
),
1867 inet_ntop (AF_INET
, &lsa
->data
->adv_router
,
1868 buf3
, INET_ADDRSTRLEN
));
1869 zlog_err("OSPF domain compromised by attack or corruption. "
1870 "Verify correct operation of -ALL- OSPF routers.");
1871 DISCARD_LSA (lsa
, 0);
1874 /* Find the LSA in the current database. */
1876 current
= ospf_lsa_lookup_by_header (oi
->area
, lsa
->data
);
1878 /* (4) If the LSA's LS age is equal to MaxAge, and there is currently
1879 no instance of the LSA in the router's link state database,
1880 and none of router's neighbors are in states Exchange or Loading,
1881 then take the following actions: */
1883 if (IS_LSA_MAXAGE (lsa
) && !current
&&
1884 ospf_check_nbr_status(oi
->ospf
))
1886 /* (4a) Response Link State Acknowledgment. */
1887 ospf_ls_ack_send (nbr
, lsa
);
1889 /* (4b) Discard LSA. */
1890 if (IS_DEBUG_OSPF (lsa
, LSA
))
1892 zlog_debug ("Link State Update[%s]: LS age is equal to MaxAge.",
1895 DISCARD_LSA (lsa
, 3);
1898 if (IS_OPAQUE_LSA (lsa
->data
->type
)
1899 && IPV4_ADDR_SAME (&lsa
->data
->adv_router
, &oi
->ospf
->router_id
))
1902 * Even if initial flushing seems to be completed, there might
1903 * be a case that self-originated LSA with MaxAge still remain
1904 * in the routing domain.
1905 * Just send an LSAck message to cease retransmission.
1907 if (IS_LSA_MAXAGE (lsa
))
1909 zlog_warn ("LSA[%s]: Boomerang effect?", dump_lsa_key (lsa
));
1910 ospf_ls_ack_send (nbr
, lsa
);
1911 ospf_lsa_discard (lsa
);
1913 if (current
!= NULL
&& ! IS_LSA_MAXAGE (current
))
1914 ospf_opaque_lsa_refresh_schedule (current
);
1919 * If an instance of self-originated Opaque-LSA is not found
1920 * in the LSDB, there are some possible cases here.
1922 * 1) This node lost opaque-capability after restart.
1923 * 2) Else, a part of opaque-type is no more supported.
1924 * 3) Else, a part of opaque-id is no more supported.
1926 * Anyway, it is still this node's responsibility to flush it.
1927 * Otherwise, the LSA instance remains in the routing domain
1928 * until its age reaches to MaxAge.
1930 /* XXX: We should deal with this for *ALL* LSAs, not just opaque */
1931 if (current
== NULL
)
1933 if (IS_DEBUG_OSPF_EVENT
)
1934 zlog_debug ("LSA[%s]: Previously originated Opaque-LSA,"
1935 "not found in the LSDB.", dump_lsa_key (lsa
));
1937 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
1939 ospf_opaque_self_originated_lsa_received (nbr
, lsa
);
1940 ospf_ls_ack_send (nbr
, lsa
);
1946 /* It might be happen that received LSA is self-originated network LSA, but
1947 * router ID is changed. So, we should check if LSA is a network-LSA whose
1948 * Link State ID is one of the router's own IP interface addresses but whose
1949 * Advertising Router is not equal to the router's own Router ID
1950 * According to RFC 2328 12.4.2 and 13.4 this LSA should be flushed.
1953 if(lsa
->data
->type
== OSPF_NETWORK_LSA
)
1955 struct listnode
*oinode
, *oinnode
;
1956 struct ospf_interface
*out_if
;
1959 for (ALL_LIST_ELEMENTS (oi
->ospf
->oiflist
, oinode
, oinnode
, out_if
))
1964 if((IPV4_ADDR_SAME(&out_if
->address
->u
.prefix4
, &lsa
->data
->id
)) &&
1965 (!(IPV4_ADDR_SAME(&oi
->ospf
->router_id
, &lsa
->data
->adv_router
))))
1967 if(out_if
->network_lsa_self
)
1969 ospf_lsa_flush_area(lsa
,out_if
->area
);
1970 if(IS_DEBUG_OSPF_EVENT
)
1971 zlog_debug ("ospf_lsa_discard() in ospf_ls_upd() point 9: lsa %p Type-%d",
1972 (void *)lsa
, (int) lsa
->data
->type
);
1973 ospf_lsa_discard (lsa
);
1983 /* (5) Find the instance of this LSA that is currently contained
1984 in the router's link state database. If there is no
1985 database copy, or the received LSA is more recent than
1986 the database copy the following steps must be performed.
1987 (The sub steps from RFC 2328 section 13 step (5) will be performed in
1990 if (current
== NULL
||
1991 (ret
= ospf_lsa_more_recent (current
, lsa
)) < 0)
1993 /* Actual flooding procedure. */
1994 if (ospf_flood (oi
->ospf
, nbr
, current
, lsa
) < 0) /* Trap NSSA later. */
1995 DISCARD_LSA (lsa
, 4);
1999 /* (6) Else, If there is an instance of the LSA on the sending
2000 neighbor's Link state request list, an error has occurred in
2001 the Database Exchange process. In this case, restart the
2002 Database Exchange process by generating the neighbor event
2003 BadLSReq for the sending neighbor and stop processing the
2004 Link State Update packet. */
2006 if (ospf_ls_request_lookup (nbr
, lsa
))
2008 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
2009 zlog_warn("LSA[%s] instance exists on Link state request list",
2012 /* Clean list of LSAs. */
2013 ospf_upd_list_clean (lsas
);
2014 /* this lsa is not on lsas list already. */
2015 ospf_lsa_discard (lsa
);
2019 /* If the received LSA is the same instance as the database copy
2020 (i.e., neither one is more recent) the following two steps
2021 should be performed: */
2025 /* If the LSA is listed in the Link state retransmission list
2026 for the receiving adjacency, the router itself is expecting
2027 an acknowledgment for this LSA. The router should treat the
2028 received LSA as an acknowledgment by removing the LSA from
2029 the Link state retransmission list. This is termed an
2030 "implied acknowledgment". */
2032 ls_ret
= ospf_ls_retransmit_lookup (nbr
, lsa
);
2036 ospf_ls_retransmit_delete (nbr
, ls_ret
);
2038 /* Delayed acknowledgment sent if advertisement received
2039 from Designated Router, otherwise do nothing. */
2040 if (oi
->state
== ISM_Backup
)
2041 if (NBR_IS_DR (nbr
))
2042 listnode_add (oi
->ls_ack
, ospf_lsa_lock (lsa
));
2044 DISCARD_LSA (lsa
, 5);
2047 /* Acknowledge the receipt of the LSA by sending a
2048 Link State Acknowledgment packet back out the receiving
2051 ospf_ls_ack_send (nbr
, lsa
);
2052 DISCARD_LSA (lsa
, 6);
2056 /* The database copy is more recent. If the database copy
2057 has LS age equal to MaxAge and LS sequence number equal to
2058 MaxSequenceNumber, simply discard the received LSA without
2059 acknowledging it. (In this case, the LSA's LS sequence number is
2060 wrapping, and the MaxSequenceNumber LSA must be completely
2061 flushed before any new LSA instance can be introduced). */
2063 else if (ret
> 0) /* Database copy is more recent */
2065 if (IS_LSA_MAXAGE (current
) &&
2066 current
->data
->ls_seqnum
== htonl (OSPF_MAX_SEQUENCE_NUMBER
))
2068 DISCARD_LSA (lsa
, 7);
2070 /* Otherwise, as long as the database copy has not been sent in a
2071 Link State Update within the last MinLSArrival seconds, send the
2072 database copy back to the sending neighbor, encapsulated within
2073 a Link State Update Packet. The Link State Update Packet should
2074 be sent directly to the neighbor. In so doing, do not put the
2075 database copy of the LSA on the neighbor's link state
2076 retransmission list, and do not acknowledge the received (less
2077 recent) LSA instance. */
2080 if (monotime_since (¤t
->tv_orig
, NULL
)
2081 >= ospf
->min_ls_arrival
* 1000LL)
2082 /* Trap NSSA type later.*/
2083 ospf_ls_upd_send_lsa (nbr
, current
, OSPF_SEND_PACKET_DIRECT
);
2084 DISCARD_LSA (lsa
, 8);
2090 assert (listcount (lsas
) == 0);
2094 /* OSPF Link State Acknowledgment message read -- RFC2328 Section 13.7. */
2096 ospf_ls_ack (struct ip
*iph
, struct ospf_header
*ospfh
,
2097 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
2099 struct ospf_neighbor
*nbr
;
2101 /* increment statistics. */
2104 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
2107 zlog_warn ("Link State Acknowledgment: Unknown Neighbor %s.",
2108 inet_ntoa (ospfh
->router_id
));
2112 /* Add event to thread. */
2113 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_PacketReceived
);
2115 if (nbr
->state
< NSM_Exchange
)
2117 if (IS_DEBUG_OSPF (nsm
, NSM_EVENTS
))
2118 zlog_debug ("Link State Acknowledgment: "
2119 "Neighbor[%s] state %s is less than Exchange",
2120 inet_ntoa (ospfh
->router_id
),
2121 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
2125 while (size
>= OSPF_LSA_HEADER_SIZE
)
2127 struct ospf_lsa
*lsa
, *lsr
;
2129 lsa
= ospf_lsa_new ();
2130 lsa
->data
= (struct lsa_header
*) STREAM_PNT (s
);
2132 /* lsah = (struct lsa_header *) STREAM_PNT (s); */
2133 size
-= OSPF_LSA_HEADER_SIZE
;
2134 stream_forward_getp (s
, OSPF_LSA_HEADER_SIZE
);
2136 if (lsa
->data
->type
< OSPF_MIN_LSA
|| lsa
->data
->type
>= OSPF_MAX_LSA
)
2139 ospf_lsa_discard (lsa
);
2143 lsr
= ospf_ls_retransmit_lookup (nbr
, lsa
);
2145 if (lsr
!= NULL
&& ospf_lsa_more_recent (lsr
, lsa
) == 0)
2146 ospf_ls_retransmit_delete (nbr
, lsr
);
2149 ospf_lsa_discard (lsa
);
2155 static struct stream
*
2156 ospf_recv_packet (int fd
, struct interface
**ifp
, struct stream
*ibuf
)
2161 ifindex_t ifindex
= 0;
2163 /* Header and data both require alignment. */
2164 char buff
[CMSG_SPACE(SOPT_SIZE_CMSG_IFINDEX_IPV4())];
2167 memset (&msgh
, 0, sizeof (struct msghdr
));
2168 msgh
.msg_iov
= &iov
;
2169 msgh
.msg_iovlen
= 1;
2170 msgh
.msg_control
= (caddr_t
) buff
;
2171 msgh
.msg_controllen
= sizeof (buff
);
2173 ret
= stream_recvmsg (ibuf
, fd
, &msgh
, 0, OSPF_MAX_PACKET_SIZE
+1);
2176 zlog_warn("stream_recvmsg failed: %s", safe_strerror(errno
));
2179 if ((unsigned int)ret
< sizeof(iph
)) /* ret must be > 0 now */
2181 zlog_warn("ospf_recv_packet: discarding runt packet of length %d "
2182 "(ip header size is %u)",
2183 ret
, (u_int
)sizeof(iph
));
2187 /* Note that there should not be alignment problems with this assignment
2188 because this is at the beginning of the stream data buffer. */
2189 iph
= (struct ip
*) STREAM_DATA(ibuf
);
2190 sockopt_iphdrincl_swab_systoh (iph
);
2192 ip_len
= iph
->ip_len
;
2194 #if !defined(GNU_LINUX) && (OpenBSD < 200311) && (__FreeBSD_version < 1000000)
2196 * Kernel network code touches incoming IP header parameters,
2197 * before protocol specific processing.
2199 * 1) Convert byteorder to host representation.
2200 * --> ip_len, ip_id, ip_off
2202 * 2) Adjust ip_len to strip IP header size!
2203 * --> If user process receives entire IP packet via RAW
2204 * socket, it must consider adding IP header size to
2205 * the "ip_len" field of "ip" structure.
2207 * For more details, see <netinet/ip_input.c>.
2209 ip_len
= ip_len
+ (iph
->ip_hl
<< 2);
2212 #if defined(__DragonFly__)
2214 * in DragonFly's raw socket, ip_len/ip_off are read
2215 * in network byte order.
2216 * As OpenBSD < 200311 adjust ip_len to strip IP header size!
2218 ip_len
= ntohs(iph
->ip_len
) + (iph
->ip_hl
<< 2);
2221 ifindex
= getsockopt_ifindex (AF_INET
, &msgh
);
2223 *ifp
= if_lookup_by_index (ifindex
, VRF_DEFAULT
);
2227 zlog_warn ("ospf_recv_packet read length mismatch: ip_len is %d, "
2228 "but recvmsg returned %d", ip_len
, ret
);
2235 static struct ospf_interface
*
2236 ospf_associate_packet_vl (struct ospf
*ospf
, struct interface
*ifp
,
2237 struct ip
*iph
, struct ospf_header
*ospfh
)
2239 struct ospf_interface
*rcv_oi
;
2240 struct ospf_vl_data
*vl_data
;
2241 struct ospf_area
*vl_area
;
2242 struct listnode
*node
;
2244 if (IN_MULTICAST (ntohl (iph
->ip_dst
.s_addr
)) ||
2245 !OSPF_IS_AREA_BACKBONE (ospfh
))
2248 /* look for local OSPF interface matching the destination
2249 * to determine Area ID. We presume therefore the destination address
2250 * is unique, or at least (for "unnumbered" links), not used in other
2253 if ((rcv_oi
= ospf_if_lookup_by_local_addr (ospf
, NULL
,
2254 iph
->ip_dst
)) == NULL
)
2257 for (ALL_LIST_ELEMENTS_RO (ospf
->vlinks
, node
, vl_data
))
2259 vl_area
= ospf_area_lookup_by_area_id (ospf
, vl_data
->vl_area_id
);
2263 if (OSPF_AREA_SAME (&vl_area
, &rcv_oi
->area
) &&
2264 IPV4_ADDR_SAME (&vl_data
->vl_peer
, &ospfh
->router_id
))
2266 if (IS_DEBUG_OSPF_EVENT
)
2267 zlog_debug ("associating packet with %s",
2268 IF_NAME (vl_data
->vl_oi
));
2269 if (! CHECK_FLAG (vl_data
->vl_oi
->ifp
->flags
, IFF_UP
))
2271 if (IS_DEBUG_OSPF_EVENT
)
2272 zlog_debug ("This VL is not up yet, sorry");
2276 return vl_data
->vl_oi
;
2280 if (IS_DEBUG_OSPF_EVENT
)
2281 zlog_debug ("couldn't find any VL to associate the packet with");
2287 ospf_check_area_id (struct ospf_interface
*oi
, struct ospf_header
*ospfh
)
2289 /* Check match the Area ID of the receiving interface. */
2290 if (OSPF_AREA_SAME (&oi
->area
, &ospfh
))
2296 /* Unbound socket will accept any Raw IP packets if proto is matched.
2297 To prevent it, compare src IP address and i/f address with masking
2298 i/f network mask. */
2300 ospf_check_network_mask (struct ospf_interface
*oi
, struct in_addr ip_src
)
2302 struct in_addr mask
, me
, him
;
2304 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
||
2305 oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
2308 masklen2ip (oi
->address
->prefixlen
, &mask
);
2310 me
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
2311 him
.s_addr
= ip_src
.s_addr
& mask
.s_addr
;
2313 if (IPV4_ADDR_SAME (&me
, &him
))
2319 /* Return 1, if the packet is properly authenticated and checksummed,
2320 0 otherwise. In particular, check that AuType header field is valid and
2321 matches the locally configured AuType, and that D.5 requirements are met. */
2323 ospf_check_auth (struct ospf_interface
*oi
, struct ospf_header
*ospfh
)
2325 struct crypt_key
*ck
;
2326 u_int16_t iface_auth_type
;
2327 u_int16_t pkt_auth_type
= ntohs (ospfh
->auth_type
);
2329 switch (pkt_auth_type
)
2331 case OSPF_AUTH_NULL
: /* RFC2328 D.5.1 */
2332 if (OSPF_AUTH_NULL
!= (iface_auth_type
= ospf_auth_type (oi
)))
2334 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2335 zlog_warn ("interface %s: auth-type mismatch, local %s, rcvd Null",
2336 IF_NAME (oi
), lookup_msg(ospf_auth_type_str
, iface_auth_type
, NULL
));
2339 if (! ospf_check_sum (ospfh
))
2341 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2342 zlog_warn ("interface %s: Null auth OK, but checksum error, Router-ID %s",
2343 IF_NAME (oi
), inet_ntoa (ospfh
->router_id
));
2347 case OSPF_AUTH_SIMPLE
: /* RFC2328 D.5.2 */
2348 if (OSPF_AUTH_SIMPLE
!= (iface_auth_type
= ospf_auth_type (oi
)))
2350 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2351 zlog_warn ("interface %s: auth-type mismatch, local %s, rcvd Simple",
2352 IF_NAME (oi
), lookup_msg(ospf_auth_type_str
, iface_auth_type
, NULL
));
2355 if (memcmp (OSPF_IF_PARAM (oi
, auth_simple
), ospfh
->u
.auth_data
, OSPF_AUTH_SIMPLE_SIZE
))
2357 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2358 zlog_warn ("interface %s: Simple auth failed", IF_NAME (oi
));
2361 if (! ospf_check_sum (ospfh
))
2363 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2364 zlog_warn ("interface %s: Simple auth OK, checksum error, Router-ID %s",
2365 IF_NAME (oi
), inet_ntoa (ospfh
->router_id
));
2369 case OSPF_AUTH_CRYPTOGRAPHIC
: /* RFC2328 D.5.3 */
2370 if (OSPF_AUTH_CRYPTOGRAPHIC
!= (iface_auth_type
= ospf_auth_type (oi
)))
2372 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2373 zlog_warn ("interface %s: auth-type mismatch, local %s, rcvd Cryptographic",
2374 IF_NAME (oi
), lookup_msg(ospf_auth_type_str
, iface_auth_type
, NULL
));
2377 if (ospfh
->checksum
)
2379 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2380 zlog_warn ("interface %s: OSPF header checksum is not 0", IF_NAME (oi
));
2383 /* only MD5 crypto method can pass ospf_packet_examin() */
2386 NULL
== (ck
= listgetdata (listtail(OSPF_IF_PARAM (oi
,auth_crypt
)))) ||
2387 ospfh
->u
.crypt
.key_id
!= ck
->key_id
||
2388 /* Condition above uses the last key ID on the list, which is
2389 different from what ospf_crypt_key_lookup() does. A bug? */
2390 ! ospf_check_md5_digest (oi
, ospfh
)
2393 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2394 zlog_warn ("interface %s: MD5 auth failed", IF_NAME (oi
));
2399 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2400 zlog_warn ("interface %s: invalid packet auth-type (%02x)",
2401 IF_NAME (oi
), pkt_auth_type
);
2407 ospf_check_sum (struct ospf_header
*ospfh
)
2412 /* clear auth_data for checksum. */
2413 memset (ospfh
->u
.auth_data
, 0, OSPF_AUTH_SIMPLE_SIZE
);
2415 /* keep checksum and clear. */
2416 sum
= ospfh
->checksum
;
2417 memset (&ospfh
->checksum
, 0, sizeof (u_int16_t
));
2419 /* calculate checksum. */
2420 ret
= in_cksum (ospfh
, ntohs (ospfh
->length
));
2424 zlog_info ("ospf_check_sum(): checksum mismatch, my %X, his %X",
2432 /* Verify, that given link/TOS records are properly sized/aligned and match
2433 Router-LSA "# links" and "# TOS" fields as specified in RFC2328 A.4.2. */
2435 ospf_router_lsa_links_examin
2437 struct router_lsa_link
* link
,
2438 u_int16_t linkbytes
,
2439 const u_int16_t num_links
2442 unsigned counted_links
= 0, thislinklen
;
2446 thislinklen
= OSPF_ROUTER_LSA_LINK_SIZE
+ 4 * link
->m
[0].tos_count
;
2447 if (thislinklen
> linkbytes
)
2449 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2450 zlog_debug ("%s: length error in link block #%u", __func__
, counted_links
);
2453 link
= (struct router_lsa_link
*)((caddr_t
) link
+ thislinklen
);
2454 linkbytes
-= thislinklen
;
2457 if (counted_links
!= num_links
)
2459 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2460 zlog_debug ("%s: %u link blocks declared, %u present",
2461 __func__
, num_links
, counted_links
);
2467 /* Verify, that the given LSA is properly sized/aligned (including type-specific
2468 minimum length constraint). */
2470 ospf_lsa_examin (struct lsa_header
* lsah
, const u_int16_t lsalen
, const u_char headeronly
)
2473 struct router_lsa
* rlsa
;
2476 lsah
->type
< OSPF_MAX_LSA
&&
2477 ospf_lsa_minlen
[lsah
->type
] &&
2478 lsalen
< OSPF_LSA_HEADER_SIZE
+ ospf_lsa_minlen
[lsah
->type
]
2481 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2482 zlog_debug ("%s: undersized (%u B) %s",
2483 __func__
, lsalen
, lookup_msg(ospf_lsa_type_msg
, lsah
->type
, NULL
));
2488 case OSPF_ROUTER_LSA
:
2489 /* RFC2328 A.4.2, LSA header + 4 bytes followed by N>=1 (12+)-byte link blocks */
2492 ret
= (lsalen
- OSPF_LSA_HEADER_SIZE
- OSPF_ROUTER_LSA_MIN_SIZE
) % 4 ? MSG_NG
: MSG_OK
;
2495 rlsa
= (struct router_lsa
*) lsah
;
2496 ret
= ospf_router_lsa_links_examin
2498 (struct router_lsa_link
*) rlsa
->link
,
2499 lsalen
- OSPF_LSA_HEADER_SIZE
- 4, /* skip: basic header, "flags", 0, "# links" */
2500 ntohs (rlsa
->links
) /* 16 bits */
2503 case OSPF_AS_EXTERNAL_LSA
:
2504 /* RFC2328 A.4.5, LSA header + 4 bytes followed by N>=1 12-bytes long blocks */
2505 case OSPF_AS_NSSA_LSA
:
2506 /* RFC3101 C, idem */
2507 ret
= (lsalen
- OSPF_LSA_HEADER_SIZE
- OSPF_AS_EXTERNAL_LSA_MIN_SIZE
) % 12 ? MSG_NG
: MSG_OK
;
2509 /* Following LSA types are considered OK length-wise as soon as their minimum
2510 * length constraint is met and length of the whole LSA is a multiple of 4
2511 * (basic LSA header size is already a multiple of 4). */
2512 case OSPF_NETWORK_LSA
:
2513 /* RFC2328 A.4.3, LSA header + 4 bytes followed by N>=1 router-IDs */
2514 case OSPF_SUMMARY_LSA
:
2515 case OSPF_ASBR_SUMMARY_LSA
:
2516 /* RFC2328 A.4.4, LSA header + 4 bytes followed by N>=1 4-bytes TOS blocks */
2517 case OSPF_OPAQUE_LINK_LSA
:
2518 case OSPF_OPAQUE_AREA_LSA
:
2519 case OSPF_OPAQUE_AS_LSA
:
2520 /* RFC5250 A.2, "some number of octets (of application-specific
2521 * data) padded to 32-bit alignment." This is considered equivalent
2522 * to 4-byte alignment of all other LSA types, see OSPF-ALIGNMENT.txt
2523 * file for the detailed analysis of this passage. */
2524 ret
= lsalen
% 4 ? MSG_NG
: MSG_OK
;
2527 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2528 zlog_debug ("%s: unsupported LSA type 0x%02x", __func__
, lsah
->type
);
2531 if (ret
!= MSG_OK
&& IS_DEBUG_OSPF_PACKET (0, RECV
))
2532 zlog_debug ("%s: alignment error in %s",
2533 __func__
, lookup_msg(ospf_lsa_type_msg
, lsah
->type
, NULL
));
2537 /* Verify if the provided input buffer is a valid sequence of LSAs. This
2538 includes verification of LSA blocks length/alignment and dispatching
2539 of deeper-level checks. */
2543 struct lsa_header
*lsah
, /* start of buffered data */
2545 const u_char headeronly
,
2546 /* When declared_num_lsas is not 0, compare it to the real number of LSAs
2547 and treat the difference as an error. */
2548 const u_int32_t declared_num_lsas
2551 u_int32_t counted_lsas
= 0;
2556 if (length
< OSPF_LSA_HEADER_SIZE
)
2558 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2559 zlog_debug ("%s: undersized (%zu B) trailing (#%u) LSA header",
2560 __func__
, length
, counted_lsas
);
2563 /* save on ntohs() calls here and in the LSA validator */
2564 lsalen
= ntohs (lsah
->length
);
2565 if (lsalen
< OSPF_LSA_HEADER_SIZE
)
2567 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2568 zlog_debug ("%s: malformed LSA header #%u, declared length is %u B",
2569 __func__
, counted_lsas
, lsalen
);
2574 /* less checks here and in ospf_lsa_examin() */
2575 if (MSG_OK
!= ospf_lsa_examin (lsah
, lsalen
, 1))
2577 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2578 zlog_debug ("%s: malformed header-only LSA #%u", __func__
, counted_lsas
);
2581 lsah
= (struct lsa_header
*) ((caddr_t
) lsah
+ OSPF_LSA_HEADER_SIZE
);
2582 length
-= OSPF_LSA_HEADER_SIZE
;
2586 /* make sure the input buffer is deep enough before further checks */
2587 if (lsalen
> length
)
2589 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2590 zlog_debug ("%s: anomaly in LSA #%u: declared length is %u B, buffered length is %zu B",
2591 __func__
, counted_lsas
, lsalen
, length
);
2594 if (MSG_OK
!= ospf_lsa_examin (lsah
, lsalen
, 0))
2596 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2597 zlog_debug ("%s: malformed LSA #%u", __func__
, counted_lsas
);
2600 lsah
= (struct lsa_header
*) ((caddr_t
) lsah
+ lsalen
);
2606 if (declared_num_lsas
&& counted_lsas
!= declared_num_lsas
)
2608 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2609 zlog_debug ("%s: #LSAs declared (%u) does not match actual (%u)",
2610 __func__
, declared_num_lsas
, counted_lsas
);
2616 /* Verify a complete OSPF packet for proper sizing/alignment. */
2618 ospf_packet_examin (struct ospf_header
* oh
, const unsigned bytesonwire
)
2620 u_int16_t bytesdeclared
, bytesauth
;
2622 struct ospf_ls_update
* lsupd
;
2624 /* Length, 1st approximation. */
2625 if (bytesonwire
< OSPF_HEADER_SIZE
)
2627 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2628 zlog_debug ("%s: undersized (%u B) packet", __func__
, bytesonwire
);
2631 /* Now it is safe to access header fields. Performing length check, allow
2632 * for possible extra bytes of crypto auth/padding, which are not counted
2633 * in the OSPF header "length" field. */
2634 if (oh
->version
!= OSPF_VERSION
)
2636 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2637 zlog_debug ("%s: invalid (%u) protocol version", __func__
, oh
->version
);
2640 bytesdeclared
= ntohs (oh
->length
);
2641 if (ntohs (oh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
2645 if (oh
->u
.crypt
.auth_data_len
!= OSPF_AUTH_MD5_SIZE
)
2647 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2648 zlog_debug ("%s: unsupported crypto auth length (%u B)",
2649 __func__
, oh
->u
.crypt
.auth_data_len
);
2652 bytesauth
= OSPF_AUTH_MD5_SIZE
;
2654 if (bytesdeclared
+ bytesauth
> bytesonwire
)
2656 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2657 zlog_debug ("%s: packet length error (%u real, %u+%u declared)",
2658 __func__
, bytesonwire
, bytesdeclared
, bytesauth
);
2661 /* Length, 2nd approximation. The type-specific constraint is checked
2662 against declared length, not amount of bytes on wire. */
2665 oh
->type
>= OSPF_MSG_HELLO
&&
2666 oh
->type
<= OSPF_MSG_LS_ACK
&&
2667 bytesdeclared
< OSPF_HEADER_SIZE
+ ospf_packet_minlen
[oh
->type
]
2670 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2671 zlog_debug ("%s: undersized (%u B) %s packet", __func__
,
2672 bytesdeclared
, lookup_msg(ospf_packet_type_str
, oh
->type
, NULL
));
2677 case OSPF_MSG_HELLO
:
2678 /* RFC2328 A.3.2, packet header + OSPF_HELLO_MIN_SIZE bytes followed
2679 by N>=0 router-IDs. */
2680 ret
= (bytesdeclared
- OSPF_HEADER_SIZE
- OSPF_HELLO_MIN_SIZE
) % 4 ? MSG_NG
: MSG_OK
;
2682 case OSPF_MSG_DB_DESC
:
2683 /* RFC2328 A.3.3, packet header + OSPF_DB_DESC_MIN_SIZE bytes followed
2684 by N>=0 header-only LSAs. */
2685 ret
= ospf_lsaseq_examin
2687 (struct lsa_header
*) ((caddr_t
) oh
+ OSPF_HEADER_SIZE
+ OSPF_DB_DESC_MIN_SIZE
),
2688 bytesdeclared
- OSPF_HEADER_SIZE
- OSPF_DB_DESC_MIN_SIZE
,
2689 1, /* header-only LSAs */
2693 case OSPF_MSG_LS_REQ
:
2694 /* RFC2328 A.3.4, packet header followed by N>=0 12-bytes request blocks. */
2695 ret
= (bytesdeclared
- OSPF_HEADER_SIZE
- OSPF_LS_REQ_MIN_SIZE
) %
2696 OSPF_LSA_KEY_SIZE
? MSG_NG
: MSG_OK
;
2698 case OSPF_MSG_LS_UPD
:
2699 /* RFC2328 A.3.5, packet header + OSPF_LS_UPD_MIN_SIZE bytes followed
2700 by N>=0 full LSAs (with N declared beforehand). */
2701 lsupd
= (struct ospf_ls_update
*) ((caddr_t
) oh
+ OSPF_HEADER_SIZE
);
2702 ret
= ospf_lsaseq_examin
2704 (struct lsa_header
*) ((caddr_t
) lsupd
+ OSPF_LS_UPD_MIN_SIZE
),
2705 bytesdeclared
- OSPF_HEADER_SIZE
- OSPF_LS_UPD_MIN_SIZE
,
2707 ntohl (lsupd
->num_lsas
) /* 32 bits */
2710 case OSPF_MSG_LS_ACK
:
2711 /* RFC2328 A.3.6, packet header followed by N>=0 header-only LSAs. */
2712 ret
= ospf_lsaseq_examin
2714 (struct lsa_header
*) ((caddr_t
) oh
+ OSPF_HEADER_SIZE
+ OSPF_LS_ACK_MIN_SIZE
),
2715 bytesdeclared
- OSPF_HEADER_SIZE
- OSPF_LS_ACK_MIN_SIZE
,
2716 1, /* header-only LSAs */
2721 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2722 zlog_debug ("%s: invalid packet type 0x%02x", __func__
, oh
->type
);
2725 if (ret
!= MSG_OK
&& IS_DEBUG_OSPF_PACKET (0, RECV
))
2726 zlog_debug ("%s: malformed %s packet", __func__
, lookup_msg(ospf_packet_type_str
, oh
->type
, NULL
));
2730 /* OSPF Header verification. */
2732 ospf_verify_header (struct stream
*ibuf
, struct ospf_interface
*oi
,
2733 struct ip
*iph
, struct ospf_header
*ospfh
)
2735 /* Check Area ID. */
2736 if (!ospf_check_area_id (oi
, ospfh
))
2738 zlog_warn ("interface %s: ospf_read invalid Area ID %s.",
2739 IF_NAME (oi
), inet_ntoa (ospfh
->area_id
));
2743 /* Check network mask, Silently discarded. */
2744 if (! ospf_check_network_mask (oi
, iph
->ip_src
))
2746 zlog_warn ("interface %s: ospf_read network address is not same [%s]",
2747 IF_NAME (oi
), inet_ntoa (iph
->ip_src
));
2751 /* Check authentication. The function handles logging actions, where required. */
2752 if (! ospf_check_auth (oi
, ospfh
))
2758 /* Starting point of packet process function. */
2760 ospf_read (struct thread
*thread
)
2763 struct stream
*ibuf
;
2765 struct ospf_interface
*oi
;
2767 struct ospf_header
*ospfh
;
2769 struct interface
*ifp
;
2770 struct connected
*c
;
2772 /* first of all get interface pointer. */
2773 ospf
= THREAD_ARG (thread
);
2775 /* prepare for next packet. */
2776 ospf
->t_read
= NULL
;
2777 thread_add_read(master
, ospf_read
, ospf
, ospf
->fd
, &ospf
->t_read
);
2779 stream_reset(ospf
->ibuf
);
2780 if (!(ibuf
= ospf_recv_packet (ospf
->fd
, &ifp
, ospf
->ibuf
)))
2782 /* This raw packet is known to be at least as big as its IP header. */
2784 /* Note that there should not be alignment problems with this assignment
2785 because this is at the beginning of the stream data buffer. */
2786 iph
= (struct ip
*) STREAM_DATA (ibuf
);
2787 /* Note that sockopt_iphdrincl_swab_systoh was called in ospf_recv_packet. */
2791 /* Handle cases where the platform does not support retrieving the ifindex,
2792 and also platforms (such as Solaris 8) that claim to support ifindex
2793 retrieval but do not. */
2794 c
= if_lookup_address ((void *)&iph
->ip_src
, AF_INET
, VRF_DEFAULT
);
2801 /* IP Header dump. */
2802 if (IS_DEBUG_OSPF_PACKET(0, RECV
))
2803 ospf_ip_header_dump (iph
);
2805 /* Self-originated packet should be discarded silently. */
2806 if (ospf_if_lookup_by_local_addr (ospf
, NULL
, iph
->ip_src
))
2808 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2810 zlog_debug ("ospf_read[%s]: Dropping self-originated packet",
2811 inet_ntoa (iph
->ip_src
));
2816 /* Advance from IP header to OSPF header (iph->ip_hl has been verified
2817 by ospf_recv_packet() to be correct). */
2818 stream_forward_getp (ibuf
, iph
->ip_hl
* 4);
2820 ospfh
= (struct ospf_header
*) STREAM_PNT (ibuf
);
2821 if (MSG_OK
!= ospf_packet_examin (ospfh
, stream_get_endp (ibuf
) - stream_get_getp (ibuf
)))
2823 /* Now it is safe to access all fields of OSPF packet header. */
2825 /* associate packet with ospf interface */
2826 oi
= ospf_if_lookup_recv_if (ospf
, iph
->ip_src
, ifp
);
2828 /* ospf_verify_header() relies on a valid "oi" and thus can be called only
2829 after the passive/backbone/other checks below are passed. These checks
2830 in turn access the fields of unverified "ospfh" structure for their own
2831 purposes and must remain very accurate in doing this. */
2833 /* If incoming interface is passive one, ignore it. */
2834 if (oi
&& OSPF_IF_PASSIVE_STATUS (oi
) == OSPF_IF_PASSIVE
)
2836 char buf
[3][INET_ADDRSTRLEN
];
2838 if (IS_DEBUG_OSPF_EVENT
)
2839 zlog_debug ("ignoring packet from router %s sent to %s, "
2840 "received on a passive interface, %s",
2841 inet_ntop(AF_INET
, &ospfh
->router_id
, buf
[0], sizeof(buf
[0])),
2842 inet_ntop(AF_INET
, &iph
->ip_dst
, buf
[1], sizeof(buf
[1])),
2843 inet_ntop(AF_INET
, &oi
->address
->u
.prefix4
,
2844 buf
[2], sizeof(buf
[2])));
2846 if (iph
->ip_dst
.s_addr
== htonl(OSPF_ALLSPFROUTERS
))
2848 /* Try to fix multicast membership.
2849 * Some OS:es may have problems in this area,
2850 * make sure it is removed.
2852 OI_MEMBER_JOINED(oi
, MEMBER_ALLROUTERS
);
2853 ospf_if_set_multicast(oi
);
2859 /* if no local ospf_interface,
2860 * or header area is backbone but ospf_interface is not
2861 * check for VLINK interface
2863 if ( (oi
== NULL
) ||
2864 (OSPF_IS_AREA_ID_BACKBONE(ospfh
->area_id
)
2865 && !OSPF_IS_AREA_ID_BACKBONE(oi
->area
->area_id
))
2868 if ((oi
= ospf_associate_packet_vl (ospf
, ifp
, iph
, ospfh
)) == NULL
)
2870 if (!ospf
->instance
&& IS_DEBUG_OSPF_EVENT
)
2871 zlog_debug ("Packet from [%s] received on link %s"
2872 " but no ospf_interface",
2873 inet_ntoa (iph
->ip_src
), ifp
->name
);
2878 /* else it must be a local ospf interface, check it was received on
2881 else if (oi
->ifp
!= ifp
)
2883 if (IS_DEBUG_OSPF_EVENT
)
2884 zlog_warn ("Packet from [%s] received on wrong link %s",
2885 inet_ntoa (iph
->ip_src
), ifp
->name
);
2888 else if (oi
->state
== ISM_Down
)
2890 char buf
[2][INET_ADDRSTRLEN
];
2891 zlog_warn ("Ignoring packet from %s to %s received on interface that is "
2892 "down [%s]; interface flags are %s",
2893 inet_ntop(AF_INET
, &iph
->ip_src
, buf
[0], sizeof(buf
[0])),
2894 inet_ntop(AF_INET
, &iph
->ip_dst
, buf
[1], sizeof(buf
[1])),
2895 ifp
->name
, if_flag_dump(ifp
->flags
));
2896 /* Fix multicast memberships? */
2897 if (iph
->ip_dst
.s_addr
== htonl(OSPF_ALLSPFROUTERS
))
2898 OI_MEMBER_JOINED(oi
, MEMBER_ALLROUTERS
);
2899 else if (iph
->ip_dst
.s_addr
== htonl(OSPF_ALLDROUTERS
))
2900 OI_MEMBER_JOINED(oi
, MEMBER_DROUTERS
);
2901 if (oi
->multicast_memberships
)
2902 ospf_if_set_multicast(oi
);
2907 * If the received packet is destined for AllDRouters, the packet
2908 * should be accepted only if the received ospf interface state is
2909 * either DR or Backup -- endo.
2911 if (iph
->ip_dst
.s_addr
== htonl (OSPF_ALLDROUTERS
)
2912 && (oi
->state
!= ISM_DR
&& oi
->state
!= ISM_Backup
))
2914 zlog_warn ("Dropping packet for AllDRouters from [%s] via [%s] (ISM: %s)",
2915 inet_ntoa (iph
->ip_src
), IF_NAME (oi
),
2916 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
));
2917 /* Try to fix multicast membership. */
2918 SET_FLAG(oi
->multicast_memberships
, MEMBER_DROUTERS
);
2919 ospf_if_set_multicast(oi
);
2923 /* Verify more OSPF header fields. */
2924 ret
= ospf_verify_header (ibuf
, oi
, iph
, ospfh
);
2927 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2928 zlog_debug ("ospf_read[%s]: Header check failed, "
2930 inet_ntoa (iph
->ip_src
));
2934 /* Show debug receiving packet. */
2935 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2937 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, DETAIL
))
2939 zlog_debug ("-----------------------------------------------------");
2940 ospf_packet_dump (ibuf
);
2943 zlog_debug ("%s received from [%s] via [%s]",
2944 lookup_msg(ospf_packet_type_str
, ospfh
->type
, NULL
),
2945 inet_ntoa (ospfh
->router_id
), IF_NAME (oi
));
2946 zlog_debug (" src [%s],", inet_ntoa (iph
->ip_src
));
2947 zlog_debug (" dst [%s]", inet_ntoa (iph
->ip_dst
));
2949 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, DETAIL
))
2950 zlog_debug ("-----------------------------------------------------");
2953 stream_forward_getp (ibuf
, OSPF_HEADER_SIZE
);
2955 /* Adjust size to message length. */
2956 length
= ntohs (ospfh
->length
) - OSPF_HEADER_SIZE
;
2958 /* Read rest of the packet and call each sort of packet routine. */
2959 switch (ospfh
->type
)
2961 case OSPF_MSG_HELLO
:
2962 ospf_hello (iph
, ospfh
, ibuf
, oi
, length
);
2964 case OSPF_MSG_DB_DESC
:
2965 ospf_db_desc (iph
, ospfh
, ibuf
, oi
, length
);
2967 case OSPF_MSG_LS_REQ
:
2968 ospf_ls_req (iph
, ospfh
, ibuf
, oi
, length
);
2970 case OSPF_MSG_LS_UPD
:
2971 ospf_ls_upd (ospf
, iph
, ospfh
, ibuf
, oi
, length
);
2973 case OSPF_MSG_LS_ACK
:
2974 ospf_ls_ack (iph
, ospfh
, ibuf
, oi
, length
);
2977 zlog_warn("interface %s: OSPF packet header type %d is illegal",
2978 IF_NAME(oi
), ospfh
->type
);
2985 /* Make OSPF header. */
2987 ospf_make_header (int type
, struct ospf_interface
*oi
, struct stream
*s
)
2989 struct ospf_header
*ospfh
;
2991 ospfh
= (struct ospf_header
*) STREAM_DATA (s
);
2993 ospfh
->version
= (u_char
) OSPF_VERSION
;
2994 ospfh
->type
= (u_char
) type
;
2996 ospfh
->router_id
= oi
->ospf
->router_id
;
2998 ospfh
->checksum
= 0;
2999 ospfh
->area_id
= oi
->area
->area_id
;
3000 ospfh
->auth_type
= htons (ospf_auth_type (oi
));
3002 memset (ospfh
->u
.auth_data
, 0, OSPF_AUTH_SIMPLE_SIZE
);
3004 stream_forward_endp (s
, OSPF_HEADER_SIZE
);
3007 /* Make Authentication Data. */
3009 ospf_make_auth (struct ospf_interface
*oi
, struct ospf_header
*ospfh
)
3011 struct crypt_key
*ck
;
3013 switch (ospf_auth_type (oi
))
3015 case OSPF_AUTH_NULL
:
3016 /* memset (ospfh->u.auth_data, 0, sizeof (ospfh->u.auth_data)); */
3018 case OSPF_AUTH_SIMPLE
:
3019 memcpy (ospfh
->u
.auth_data
, OSPF_IF_PARAM (oi
, auth_simple
),
3020 OSPF_AUTH_SIMPLE_SIZE
);
3022 case OSPF_AUTH_CRYPTOGRAPHIC
:
3023 /* If key is not set, then set 0. */
3024 if (list_isempty (OSPF_IF_PARAM (oi
, auth_crypt
)))
3026 ospfh
->u
.crypt
.zero
= 0;
3027 ospfh
->u
.crypt
.key_id
= 0;
3028 ospfh
->u
.crypt
.auth_data_len
= OSPF_AUTH_MD5_SIZE
;
3032 ck
= listgetdata (listtail(OSPF_IF_PARAM (oi
, auth_crypt
)));
3033 ospfh
->u
.crypt
.zero
= 0;
3034 ospfh
->u
.crypt
.key_id
= ck
->key_id
;
3035 ospfh
->u
.crypt
.auth_data_len
= OSPF_AUTH_MD5_SIZE
;
3037 /* note: the seq is done in ospf_make_md5_digest() */
3040 /* memset (ospfh->u.auth_data, 0, sizeof (ospfh->u.auth_data)); */
3047 /* Fill rest of OSPF header. */
3049 ospf_fill_header (struct ospf_interface
*oi
,
3050 struct stream
*s
, u_int16_t length
)
3052 struct ospf_header
*ospfh
;
3054 ospfh
= (struct ospf_header
*) STREAM_DATA (s
);
3057 ospfh
->length
= htons (length
);
3059 /* Calculate checksum. */
3060 if (ntohs (ospfh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
3061 ospfh
->checksum
= in_cksum (ospfh
, length
);
3063 ospfh
->checksum
= 0;
3065 /* Add Authentication Data. */
3066 ospf_make_auth (oi
, ospfh
);
3070 ospf_make_hello (struct ospf_interface
*oi
, struct stream
*s
)
3072 struct ospf_neighbor
*nbr
;
3073 struct route_node
*rn
;
3074 u_int16_t length
= OSPF_HELLO_MIN_SIZE
;
3075 struct in_addr mask
;
3079 /* Set netmask of interface. */
3080 if (!(CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
) &&
3081 oi
->type
== OSPF_IFTYPE_POINTOPOINT
) &&
3082 oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
3083 masklen2ip (oi
->address
->prefixlen
, &mask
);
3085 memset ((char *) &mask
, 0, sizeof (struct in_addr
));
3086 stream_put_ipv4 (s
, mask
.s_addr
);
3088 /* Set Hello Interval. */
3089 if (OSPF_IF_PARAM (oi
, fast_hello
) == 0)
3090 stream_putw (s
, OSPF_IF_PARAM (oi
, v_hello
));
3092 stream_putw (s
, 0); /* hello-interval of 0 for fast-hellos */
3094 if (IS_DEBUG_OSPF_EVENT
)
3095 zlog_debug ("make_hello: options: %x, int: %s",
3096 OPTIONS(oi
), IF_NAME (oi
));
3099 stream_putc (s
, OPTIONS (oi
));
3101 /* Set Router Priority. */
3102 stream_putc (s
, PRIORITY (oi
));
3104 /* Set Router Dead Interval. */
3105 stream_putl (s
, OSPF_IF_PARAM (oi
, v_wait
));
3107 /* Set Designated Router. */
3108 stream_put_ipv4 (s
, DR (oi
).s_addr
);
3110 p
= stream_get_endp (s
);
3112 /* Set Backup Designated Router. */
3113 stream_put_ipv4 (s
, BDR (oi
).s_addr
);
3115 /* Add neighbor seen. */
3116 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
3117 if ((nbr
= rn
->info
))
3118 if (nbr
->router_id
.s_addr
!= 0) /* Ignore 0.0.0.0 node. */
3119 if (nbr
->state
!= NSM_Attempt
) /* Ignore Down neighbor. */
3120 if (nbr
->state
!= NSM_Down
) /* This is myself for DR election. */
3121 if (!IPV4_ADDR_SAME (&nbr
->router_id
, &oi
->ospf
->router_id
))
3123 /* Check neighbor is sane? */
3124 if (nbr
->d_router
.s_addr
!= 0
3125 && IPV4_ADDR_SAME (&nbr
->d_router
, &oi
->address
->u
.prefix4
)
3126 && IPV4_ADDR_SAME (&nbr
->bd_router
, &oi
->address
->u
.prefix4
))
3129 stream_put_ipv4 (s
, nbr
->router_id
.s_addr
);
3133 /* Let neighbor generate BackupSeen. */
3135 stream_putl_at (s
, p
, 0); /* ipv4 address, normally */
3141 ospf_make_db_desc (struct ospf_interface
*oi
, struct ospf_neighbor
*nbr
,
3144 struct ospf_lsa
*lsa
;
3145 u_int16_t length
= OSPF_DB_DESC_MIN_SIZE
;
3149 struct ospf_lsdb
*lsdb
;
3151 /* Set Interface MTU. */
3152 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3155 stream_putw (s
, oi
->ifp
->mtu
);
3158 options
= OPTIONS (oi
);
3159 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
3160 SET_FLAG (options
, OSPF_OPTION_O
);
3161 stream_putc (s
, options
);
3164 pp
= stream_get_endp (s
);
3165 stream_putc (s
, nbr
->dd_flags
);
3167 /* Set DD Sequence Number. */
3168 stream_putl (s
, nbr
->dd_seqnum
);
3170 /* shortcut unneeded walk of (empty) summary LSDBs */
3171 if (ospf_db_summary_isempty (nbr
))
3174 /* Describe LSA Header from Database Summary List. */
3175 lsdb
= &nbr
->db_sum
;
3177 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
3179 struct route_table
*table
= lsdb
->type
[i
].db
;
3180 struct route_node
*rn
;
3182 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
3183 if ((lsa
= rn
->info
) != NULL
)
3185 if (IS_OPAQUE_LSA (lsa
->data
->type
)
3186 && (! CHECK_FLAG (options
, OSPF_OPTION_O
)))
3188 /* Suppress advertising opaque-informations. */
3189 /* Remove LSA from DB summary list. */
3190 ospf_lsdb_delete (lsdb
, lsa
);
3194 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_DISCARD
))
3196 struct lsa_header
*lsah
;
3199 /* DD packet overflows interface MTU. */
3200 if (length
+ OSPF_LSA_HEADER_SIZE
> ospf_packet_max (oi
))
3203 /* Keep pointer to LS age. */
3204 lsah
= (struct lsa_header
*) (STREAM_DATA (s
) +
3205 stream_get_endp (s
));
3207 /* Proceed stream pointer. */
3208 stream_put (s
, lsa
->data
, OSPF_LSA_HEADER_SIZE
);
3209 length
+= OSPF_LSA_HEADER_SIZE
;
3212 ls_age
= LS_AGE (lsa
);
3213 lsah
->ls_age
= htons (ls_age
);
3217 /* Remove LSA from DB summary list. */
3218 ospf_lsdb_delete (lsdb
, lsa
);
3222 /* Update 'More' bit */
3223 if (ospf_db_summary_isempty (nbr
))
3226 if (nbr
->state
>= NSM_Exchange
)
3228 UNSET_FLAG (nbr
->dd_flags
, OSPF_DD_FLAG_M
);
3229 /* Rewrite DD flags */
3230 stream_putc_at (s
, pp
, nbr
->dd_flags
);
3234 assert (IS_SET_DD_M(nbr
->dd_flags
));
3241 ospf_make_ls_req_func (struct stream
*s
, u_int16_t
*length
,
3242 unsigned long delta
, struct ospf_neighbor
*nbr
,
3243 struct ospf_lsa
*lsa
)
3245 struct ospf_interface
*oi
;
3249 /* LS Request packet overflows interface MTU. */
3250 if (*length
+ delta
> ospf_packet_max(oi
))
3253 stream_putl (s
, lsa
->data
->type
);
3254 stream_put_ipv4 (s
, lsa
->data
->id
.s_addr
);
3255 stream_put_ipv4 (s
, lsa
->data
->adv_router
.s_addr
);
3257 ospf_lsa_unlock (&nbr
->ls_req_last
);
3258 nbr
->ls_req_last
= ospf_lsa_lock (lsa
);
3265 ospf_make_ls_req (struct ospf_neighbor
*nbr
, struct stream
*s
)
3267 struct ospf_lsa
*lsa
;
3268 u_int16_t length
= OSPF_LS_REQ_MIN_SIZE
;
3269 unsigned long delta
= stream_get_endp(s
)+12;
3270 struct route_table
*table
;
3271 struct route_node
*rn
;
3273 struct ospf_lsdb
*lsdb
;
3275 lsdb
= &nbr
->ls_req
;
3277 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
3279 table
= lsdb
->type
[i
].db
;
3280 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
3281 if ((lsa
= (rn
->info
)) != NULL
)
3282 if (ospf_make_ls_req_func (s
, &length
, delta
, nbr
, lsa
) == 0)
3284 route_unlock_node (rn
);
3292 ls_age_increment (struct ospf_lsa
*lsa
, int delay
)
3296 age
= IS_LSA_MAXAGE (lsa
) ? OSPF_LSA_MAXAGE
: LS_AGE (lsa
) + delay
;
3298 return (age
> OSPF_LSA_MAXAGE
? OSPF_LSA_MAXAGE
: age
);
3302 ospf_make_ls_upd (struct ospf_interface
*oi
, struct list
*update
, struct stream
*s
)
3304 struct ospf_lsa
*lsa
;
3305 struct listnode
*node
;
3306 u_int16_t length
= 0;
3307 unsigned int size_noauth
;
3308 unsigned long delta
= stream_get_endp (s
);
3312 if (IS_DEBUG_OSPF_EVENT
)
3313 zlog_debug ("ospf_make_ls_upd: Start");
3315 pp
= stream_get_endp (s
);
3316 stream_forward_endp (s
, OSPF_LS_UPD_MIN_SIZE
);
3317 length
+= OSPF_LS_UPD_MIN_SIZE
;
3319 /* Calculate amount of packet usable for data. */
3320 size_noauth
= stream_get_size(s
) - ospf_packet_authspace(oi
);
3322 while ((node
= listhead (update
)) != NULL
)
3324 struct lsa_header
*lsah
;
3327 if (IS_DEBUG_OSPF_EVENT
)
3328 zlog_debug ("ospf_make_ls_upd: List Iteration %d", count
);
3330 lsa
= listgetdata (node
);
3335 if (length
+ delta
+ ntohs (lsa
->data
->length
) > size_noauth
)
3338 /* Keep pointer to LS age. */
3339 lsah
= (struct lsa_header
*) (STREAM_DATA (s
) + stream_get_endp (s
));
3341 /* Put LSA to Link State Request. */
3342 stream_put (s
, lsa
->data
, ntohs (lsa
->data
->length
));
3345 /* each hop must increment an lsa_age by transmit_delay
3346 of OSPF interface */
3347 ls_age
= ls_age_increment (lsa
, OSPF_IF_PARAM (oi
, transmit_delay
));
3348 lsah
->ls_age
= htons (ls_age
);
3350 length
+= ntohs (lsa
->data
->length
);
3353 list_delete_node (update
, node
);
3354 ospf_lsa_unlock (&lsa
); /* oi->ls_upd_queue */
3357 /* Now set #LSAs. */
3358 stream_putl_at (s
, pp
, count
);
3360 if (IS_DEBUG_OSPF_EVENT
)
3361 zlog_debug ("ospf_make_ls_upd: Stop");
3366 ospf_make_ls_ack (struct ospf_interface
*oi
, struct list
*ack
, struct stream
*s
)
3368 struct listnode
*node
, *nnode
;
3369 u_int16_t length
= OSPF_LS_ACK_MIN_SIZE
;
3370 unsigned long delta
= stream_get_endp(s
) + 24;
3371 struct ospf_lsa
*lsa
;
3373 for (ALL_LIST_ELEMENTS (ack
, node
, nnode
, lsa
))
3377 if (length
+ delta
> ospf_packet_max (oi
))
3380 stream_put (s
, lsa
->data
, OSPF_LSA_HEADER_SIZE
);
3381 length
+= OSPF_LSA_HEADER_SIZE
;
3383 listnode_delete (ack
, lsa
);
3384 ospf_lsa_unlock (&lsa
); /* oi->ls_ack_direct.ls_ack */
3391 ospf_hello_send_sub (struct ospf_interface
*oi
, in_addr_t addr
)
3393 struct ospf_packet
*op
;
3394 u_int16_t length
= OSPF_HEADER_SIZE
;
3396 op
= ospf_packet_new (oi
->ifp
->mtu
);
3398 /* Prepare OSPF common header. */
3399 ospf_make_header (OSPF_MSG_HELLO
, oi
, op
->s
);
3401 /* Prepare OSPF Hello body. */
3402 length
+= ospf_make_hello (oi
, op
->s
);
3404 /* Fill OSPF header. */
3405 ospf_fill_header (oi
, op
->s
, length
);
3407 /* Set packet length. */
3408 op
->length
= length
;
3410 op
->dst
.s_addr
= addr
;
3412 /* Add packet to the top of the interface output queue, so that they
3413 * can't get delayed by things like long queues of LS Update packets
3415 ospf_packet_add_top (oi
, op
);
3417 /* Hook thread to write packet. */
3418 OSPF_ISM_WRITE_ON (oi
->ospf
);
3422 ospf_poll_send (struct ospf_nbr_nbma
*nbr_nbma
)
3424 struct ospf_interface
*oi
;
3429 /* If this is passive interface, do not send OSPF Hello. */
3430 if (OSPF_IF_PASSIVE_STATUS (oi
) == OSPF_IF_PASSIVE
)
3433 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
3436 if (nbr_nbma
->nbr
!= NULL
&& nbr_nbma
->nbr
->state
!= NSM_Down
)
3439 if (PRIORITY(oi
) == 0)
3442 if (nbr_nbma
->priority
== 0
3443 && oi
->state
!= ISM_DR
&& oi
->state
!= ISM_Backup
)
3446 ospf_hello_send_sub (oi
, nbr_nbma
->addr
.s_addr
);
3450 ospf_poll_timer (struct thread
*thread
)
3452 struct ospf_nbr_nbma
*nbr_nbma
;
3454 nbr_nbma
= THREAD_ARG (thread
);
3455 nbr_nbma
->t_poll
= NULL
;
3457 if (IS_DEBUG_OSPF (nsm
, NSM_TIMERS
))
3458 zlog_debug("NSM[%s:%s]: Timer (Poll timer expire)", IF_NAME(nbr_nbma
->oi
),
3459 inet_ntoa(nbr_nbma
->addr
));
3461 ospf_poll_send (nbr_nbma
);
3463 if (nbr_nbma
->v_poll
> 0)
3464 OSPF_POLL_TIMER_ON (nbr_nbma
->t_poll
, ospf_poll_timer
,
3472 ospf_hello_reply_timer (struct thread
*thread
)
3474 struct ospf_neighbor
*nbr
;
3476 nbr
= THREAD_ARG (thread
);
3477 nbr
->t_hello_reply
= NULL
;
3481 if (IS_DEBUG_OSPF (nsm
, NSM_TIMERS
))
3482 zlog_debug("NSM[%s:%s]: Timer (hello-reply timer expire)",
3483 IF_NAME(nbr
->oi
), inet_ntoa(nbr
->router_id
));
3485 ospf_hello_send_sub (nbr
->oi
, nbr
->address
.u
.prefix4
.s_addr
);
3490 /* Send OSPF Hello. */
3492 ospf_hello_send (struct ospf_interface
*oi
)
3494 /* If this is passive interface, do not send OSPF Hello. */
3495 if (OSPF_IF_PASSIVE_STATUS (oi
) == OSPF_IF_PASSIVE
)
3498 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3500 struct ospf_neighbor
*nbr
;
3501 struct route_node
*rn
;
3503 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
3504 if ((nbr
= rn
->info
))
3505 if (nbr
!= oi
->nbr_self
)
3506 if (nbr
->state
!= NSM_Down
)
3508 /* RFC 2328 Section 9.5.1
3509 If the router is not eligible to become Designated Router,
3510 it must periodically send Hello Packets to both the
3511 Designated Router and the Backup Designated Router (if they
3513 if (PRIORITY(oi
) == 0 &&
3514 IPV4_ADDR_CMP(&DR(oi
), &nbr
->address
.u
.prefix4
) &&
3515 IPV4_ADDR_CMP(&BDR(oi
), &nbr
->address
.u
.prefix4
))
3518 /* If the router is eligible to become Designated Router, it
3519 must periodically send Hello Packets to all neighbors that
3520 are also eligible. In addition, if the router is itself the
3521 Designated Router or Backup Designated Router, it must also
3522 send periodic Hello Packets to all other neighbors. */
3524 if (nbr
->priority
== 0 && oi
->state
== ISM_DROther
)
3526 /* if oi->state == Waiting, send hello to all neighbors */
3527 ospf_hello_send_sub (oi
, nbr
->address
.u
.prefix4
.s_addr
);
3532 /* Decide destination address. */
3533 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3534 ospf_hello_send_sub (oi
, oi
->vl_data
->peer_addr
.s_addr
);
3536 ospf_hello_send_sub (oi
, htonl (OSPF_ALLSPFROUTERS
));
3540 /* Send OSPF Database Description. */
3542 ospf_db_desc_send (struct ospf_neighbor
*nbr
)
3544 struct ospf_interface
*oi
;
3545 struct ospf_packet
*op
;
3546 u_int16_t length
= OSPF_HEADER_SIZE
;
3549 op
= ospf_packet_new (oi
->ifp
->mtu
);
3551 /* Prepare OSPF common header. */
3552 ospf_make_header (OSPF_MSG_DB_DESC
, oi
, op
->s
);
3554 /* Prepare OSPF Database Description body. */
3555 length
+= ospf_make_db_desc (oi
, nbr
, op
->s
);
3557 /* Fill OSPF header. */
3558 ospf_fill_header (oi
, op
->s
, length
);
3560 /* Set packet length. */
3561 op
->length
= length
;
3563 /* Decide destination address. */
3564 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3565 op
->dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3567 op
->dst
= nbr
->address
.u
.prefix4
;
3569 /* Add packet to the interface output queue. */
3570 ospf_packet_add (oi
, op
);
3572 /* Hook thread to write packet. */
3573 OSPF_ISM_WRITE_ON (oi
->ospf
);
3575 /* Remove old DD packet, then copy new one and keep in neighbor structure. */
3577 ospf_packet_free (nbr
->last_send
);
3578 nbr
->last_send
= ospf_packet_dup (op
);
3579 monotime(&nbr
->last_send_ts
);
3582 /* Re-send Database Description. */
3584 ospf_db_desc_resend (struct ospf_neighbor
*nbr
)
3586 struct ospf_interface
*oi
;
3590 /* Add packet to the interface output queue. */
3591 ospf_packet_add (oi
, ospf_packet_dup (nbr
->last_send
));
3593 /* Hook thread to write packet. */
3594 OSPF_ISM_WRITE_ON (oi
->ospf
);
3597 /* Send Link State Request. */
3599 ospf_ls_req_send (struct ospf_neighbor
*nbr
)
3601 struct ospf_interface
*oi
;
3602 struct ospf_packet
*op
;
3603 u_int16_t length
= OSPF_HEADER_SIZE
;
3606 op
= ospf_packet_new (oi
->ifp
->mtu
);
3608 /* Prepare OSPF common header. */
3609 ospf_make_header (OSPF_MSG_LS_REQ
, oi
, op
->s
);
3611 /* Prepare OSPF Link State Request body. */
3612 length
+= ospf_make_ls_req (nbr
, op
->s
);
3613 if (length
== OSPF_HEADER_SIZE
)
3615 ospf_packet_free (op
);
3619 /* Fill OSPF header. */
3620 ospf_fill_header (oi
, op
->s
, length
);
3622 /* Set packet length. */
3623 op
->length
= length
;
3625 /* Decide destination address. */
3626 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3627 op
->dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3629 op
->dst
= nbr
->address
.u
.prefix4
;
3631 /* Add packet to the interface output queue. */
3632 ospf_packet_add (oi
, op
);
3634 /* Hook thread to write packet. */
3635 OSPF_ISM_WRITE_ON (oi
->ospf
);
3637 /* Add Link State Request Retransmission Timer. */
3638 OSPF_NSM_TIMER_ON (nbr
->t_ls_req
, ospf_ls_req_timer
, nbr
->v_ls_req
);
3641 /* Send Link State Update with an LSA. */
3643 ospf_ls_upd_send_lsa (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
,
3646 struct list
*update
;
3648 update
= list_new ();
3650 listnode_add (update
, lsa
);
3651 ospf_ls_upd_send (nbr
, update
, flag
);
3653 list_delete (update
);
3656 /* Determine size for packet. Must be at least big enough to accomodate next
3657 * LSA on list, which may be bigger than MTU size.
3659 * Return pointer to new ospf_packet
3660 * NULL if we can not allocate, eg because LSA is bigger than imposed limit
3661 * on packet sizes (in which case offending LSA is deleted from update list)
3663 static struct ospf_packet
*
3664 ospf_ls_upd_packet_new (struct list
*update
, struct ospf_interface
*oi
)
3666 struct ospf_lsa
*lsa
;
3667 struct listnode
*ln
;
3669 static char warned
= 0;
3671 lsa
= listgetdata((ln
= listhead (update
)));
3674 if ((OSPF_LS_UPD_MIN_SIZE
+ ntohs (lsa
->data
->length
))
3675 > ospf_packet_max (oi
))
3679 zlog_warn ("ospf_ls_upd_packet_new: oversized LSA encountered!"
3680 "will need to fragment. Not optimal. Try divide up"
3681 " your network with areas. Use 'debug ospf packet send'"
3682 " to see details, or look at 'show ip ospf database ..'");
3686 if (IS_DEBUG_OSPF_PACKET (0, SEND
))
3687 zlog_debug ("ospf_ls_upd_packet_new: oversized LSA id:%s,"
3688 " %d bytes originated by %s, will be fragmented!",
3689 inet_ntoa (lsa
->data
->id
),
3690 ntohs (lsa
->data
->length
),
3691 inet_ntoa (lsa
->data
->adv_router
));
3694 * Allocate just enough to fit this LSA only, to avoid including other
3695 * LSAs in fragmented LSA Updates.
3697 size
= ntohs (lsa
->data
->length
) + (oi
->ifp
->mtu
- ospf_packet_max (oi
))
3698 + OSPF_LS_UPD_MIN_SIZE
;
3701 size
= oi
->ifp
->mtu
;
3703 if (size
> OSPF_MAX_PACKET_SIZE
)
3705 zlog_warn ("ospf_ls_upd_packet_new: oversized LSA id:%s too big,"
3706 " %d bytes, packet size %ld, dropping it completely."
3707 " OSPF routing is broken!",
3708 inet_ntoa (lsa
->data
->id
), ntohs (lsa
->data
->length
),
3710 list_delete_node (update
, ln
);
3714 /* IP header is built up separately by ospf_write(). This means, that we must
3715 * reduce the "affordable" size just calculated by length of an IP header.
3716 * This makes sure, that even if we manage to fill the payload with LSA data
3717 * completely, the final packet (our data plus IP header) still fits into
3718 * outgoing interface MTU. This correction isn't really meaningful for an
3719 * oversized LSA, but for consistency the correction is done for both cases.
3721 * P.S. OSPF_MAX_PACKET_SIZE above already includes IP header size
3723 return ospf_packet_new (size
- sizeof (struct ip
));
3727 ospf_ls_upd_queue_send (struct ospf_interface
*oi
, struct list
*update
,
3728 struct in_addr addr
)
3730 struct ospf_packet
*op
;
3731 u_int16_t length
= OSPF_HEADER_SIZE
;
3733 if (IS_DEBUG_OSPF_EVENT
)
3734 zlog_debug ("listcount = %d, [%s]dst %s", listcount (update
), IF_NAME(oi
),
3737 op
= ospf_ls_upd_packet_new (update
, oi
);
3739 /* Prepare OSPF common header. */
3740 ospf_make_header (OSPF_MSG_LS_UPD
, oi
, op
->s
);
3742 /* Prepare OSPF Link State Update body.
3743 * Includes Type-7 translation.
3745 length
+= ospf_make_ls_upd (oi
, update
, op
->s
);
3747 /* Fill OSPF header. */
3748 ospf_fill_header (oi
, op
->s
, length
);
3750 /* Set packet length. */
3751 op
->length
= length
;
3753 /* Decide destination address. */
3754 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3755 op
->dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3757 op
->dst
.s_addr
= addr
.s_addr
;
3759 /* Add packet to the interface output queue. */
3760 ospf_packet_add (oi
, op
);
3762 /* Hook thread to write packet. */
3763 OSPF_ISM_WRITE_ON (oi
->ospf
);
3767 ospf_ls_upd_send_queue_event (struct thread
*thread
)
3769 struct ospf_interface
*oi
= THREAD_ARG(thread
);
3770 struct route_node
*rn
;
3771 struct route_node
*rnext
;
3772 struct list
*update
;
3775 oi
->t_ls_upd_event
= NULL
;
3777 if (IS_DEBUG_OSPF_EVENT
)
3778 zlog_debug ("ospf_ls_upd_send_queue start");
3780 for (rn
= route_top (oi
->ls_upd_queue
); rn
; rn
= rnext
)
3782 rnext
= route_next (rn
);
3784 if (rn
->info
== NULL
)
3787 update
= (struct list
*)rn
->info
;
3789 ospf_ls_upd_queue_send (oi
, update
, rn
->p
.u
.prefix4
);
3791 /* list might not be empty. */
3792 if (listcount(update
) == 0)
3794 list_delete (rn
->info
);
3796 route_unlock_node (rn
);
3804 if (IS_DEBUG_OSPF_EVENT
)
3805 zlog_debug ("ospf_ls_upd_send_queue: update lists not cleared,"
3806 " %d nodes to try again, raising new event", again
);
3807 oi
->t_ls_upd_event
= NULL
;
3808 thread_add_event(master
, ospf_ls_upd_send_queue_event
, oi
, 0,
3809 &oi
->t_ls_upd_event
);
3812 if (IS_DEBUG_OSPF_EVENT
)
3813 zlog_debug ("ospf_ls_upd_send_queue stop");
3819 ospf_ls_upd_send (struct ospf_neighbor
*nbr
, struct list
*update
, int flag
)
3821 struct ospf_interface
*oi
;
3822 struct ospf_lsa
*lsa
;
3823 struct prefix_ipv4 p
;
3824 struct route_node
*rn
;
3825 struct listnode
*node
;
3830 p
.prefixlen
= IPV4_MAX_BITLEN
;
3832 /* Decide destination address. */
3833 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3834 p
.prefix
= oi
->vl_data
->peer_addr
;
3835 else if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3836 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3837 else if (flag
== OSPF_SEND_PACKET_DIRECT
)
3838 p
.prefix
= nbr
->address
.u
.prefix4
;
3839 else if (oi
->state
== ISM_DR
|| oi
->state
== ISM_Backup
)
3840 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3841 else if (oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
)
3842 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3844 p
.prefix
.s_addr
= htonl (OSPF_ALLDROUTERS
);
3846 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3848 if (flag
== OSPF_SEND_PACKET_INDIRECT
)
3849 zlog_warn ("* LS-Update is directly sent on NBMA network.");
3850 if (IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
, &p
.prefix
.s_addr
))
3851 zlog_warn ("* LS-Update is sent to myself.");
3854 rn
= route_node_get (oi
->ls_upd_queue
, (struct prefix
*) &p
);
3856 if (rn
->info
== NULL
)
3857 rn
->info
= list_new ();
3859 route_unlock_node (rn
);
3861 for (ALL_LIST_ELEMENTS_RO (update
, node
, lsa
))
3862 listnode_add (rn
->info
, ospf_lsa_lock (lsa
)); /* oi->ls_upd_queue */
3864 thread_add_event(master
, ospf_ls_upd_send_queue_event
, oi
, 0,
3865 &oi
->t_ls_upd_event
);
3869 ospf_ls_ack_send_list (struct ospf_interface
*oi
, struct list
*ack
,
3872 struct ospf_packet
*op
;
3873 u_int16_t length
= OSPF_HEADER_SIZE
;
3875 op
= ospf_packet_new (oi
->ifp
->mtu
);
3877 /* Prepare OSPF common header. */
3878 ospf_make_header (OSPF_MSG_LS_ACK
, oi
, op
->s
);
3880 /* Prepare OSPF Link State Acknowledgment body. */
3881 length
+= ospf_make_ls_ack (oi
, ack
, op
->s
);
3883 /* Fill OSPF header. */
3884 ospf_fill_header (oi
, op
->s
, length
);
3886 /* Set packet length. */
3887 op
->length
= length
;
3889 /* Decide destination address. */
3890 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3891 op
->dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3893 op
->dst
.s_addr
= dst
.s_addr
;
3895 /* Add packet to the interface output queue. */
3896 ospf_packet_add (oi
, op
);
3898 /* Hook thread to write packet. */
3899 OSPF_ISM_WRITE_ON (oi
->ospf
);
3903 ospf_ls_ack_send_event (struct thread
*thread
)
3905 struct ospf_interface
*oi
= THREAD_ARG (thread
);
3907 oi
->t_ls_ack_direct
= NULL
;
3909 while (listcount (oi
->ls_ack_direct
.ls_ack
))
3910 ospf_ls_ack_send_list (oi
, oi
->ls_ack_direct
.ls_ack
,
3911 oi
->ls_ack_direct
.dst
);
3917 ospf_ls_ack_send (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
3919 struct ospf_interface
*oi
= nbr
->oi
;
3921 if (listcount (oi
->ls_ack_direct
.ls_ack
) == 0)
3922 oi
->ls_ack_direct
.dst
= nbr
->address
.u
.prefix4
;
3924 listnode_add (oi
->ls_ack_direct
.ls_ack
, ospf_lsa_lock (lsa
));
3926 thread_add_event(master
, ospf_ls_ack_send_event
, oi
, 0,
3927 &oi
->t_ls_ack_direct
);
3930 /* Send Link State Acknowledgment delayed. */
3932 ospf_ls_ack_send_delayed (struct ospf_interface
*oi
)
3936 /* Decide destination address. */
3937 /* RFC2328 Section 13.5 On non-broadcast
3938 networks, delayed Link State Acknowledgment packets must be
3939 unicast separately over each adjacency (i.e., neighbor whose
3940 state is >= Exchange). */
3941 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3943 struct ospf_neighbor
*nbr
;
3944 struct route_node
*rn
;
3946 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
3947 if ((nbr
= rn
->info
) != NULL
)
3948 if (nbr
!= oi
->nbr_self
&& nbr
->state
>= NSM_Exchange
)
3949 while (listcount (oi
->ls_ack
))
3950 ospf_ls_ack_send_list (oi
, oi
->ls_ack
, nbr
->address
.u
.prefix4
);
3953 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3954 dst
.s_addr
= oi
->vl_data
->peer_addr
.s_addr
;
3955 else if (oi
->state
== ISM_DR
|| oi
->state
== ISM_Backup
)
3956 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3957 else if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3958 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3959 else if (oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
)
3960 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3962 dst
.s_addr
= htonl (OSPF_ALLDROUTERS
);
3964 while (listcount (oi
->ls_ack
))
3965 ospf_ls_ack_send_list (oi
, oi
->ls_ack
, dst
);
3969 * On pt-to-pt links, all OSPF control packets are sent to the multicast
3970 * address. As a result, the kernel does not need to learn the interface
3971 * MAC of the OSPF neighbor. However, in our world, this will delay
3972 * convergence. Take the case when due to a link flap, all routes now
3973 * want to use an interface which was deemed to be costlier prior to this
3974 * event. For routes that will be installed, the missing MAC will have
3975 * punt-to-CPU set on them. This may overload the CPU control path that
3976 * can be avoided if the MAC was known apriori.
3978 #define OSPF_PING_NBR_STR_MAX (8 + 40 + 20)
3980 ospf_proactively_arp (struct ospf_neighbor
*nbr
)
3982 char ping_nbr
[OSPF_PING_NBR_STR_MAX
];
3986 if (!nbr
|| !nbr
->oi
|| !nbr
->oi
->ifp
)
3989 str_ptr
= strcpy (ping_nbr
, "ping -c 1 -I ");
3990 str_ptr
= strcat (str_ptr
, nbr
->oi
->ifp
->name
);
3991 str_ptr
= strcat (str_ptr
, " ");
3992 str_ptr
= strcat (str_ptr
, inet_ntoa (nbr
->address
.u
.prefix4
));
3993 str_ptr
= strcat (str_ptr
, " > /dev/null 2>&1 &");
3994 ret
= system (ping_nbr
);
3995 if (IS_DEBUG_OSPF_EVENT
)
3996 zlog_debug ("Executed %s %s", ping_nbr
,
3997 ((ret
== 0) ? "successfully" : "but failed"));