2 * OSPF network related functions
3 * Copyright (C) 1999 Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29 #include "sockunion.h"
33 #include "ospfd/ospfd.h"
34 #include "ospfd/ospf_network.h"
35 #include "ospfd/ospf_interface.h"
36 #include "ospfd/ospf_asbr.h"
37 #include "ospfd/ospf_lsa.h"
38 #include "ospfd/ospf_lsdb.h"
39 #include "ospfd/ospf_neighbor.h"
40 #include "ospfd/ospf_packet.h"
42 /* Join to the OSPF ALL SPF ROUTERS multicast group. */
44 ospf_if_add_allspfrouters (struct ospf
*top
, struct prefix
*p
,
49 ret
= setsockopt_multicast_ipv4 (top
->fd
, IP_ADD_MEMBERSHIP
,
50 p
->u
.prefix4
, htonl (OSPF_ALLSPFROUTERS
),
53 zlog_warn ("can't setsockopt IP_ADD_MEMBERSHIP (AllSPFRouters): %s",
56 zlog_info ("interface %s join AllSPFRouters Multicast group.",
57 inet_ntoa (p
->u
.prefix4
));
63 ospf_if_drop_allspfrouters (struct ospf
*top
, struct prefix
*p
,
68 ret
= setsockopt_multicast_ipv4 (top
->fd
, IP_DROP_MEMBERSHIP
,
69 p
->u
.prefix4
, htonl (OSPF_ALLSPFROUTERS
),
72 zlog_warn("can't setsockopt IP_DROP_MEMBERSHIP (AllSPFRouters): %s",
75 zlog_info ("interface %s leave AllSPFRouters Multicast group.",
76 inet_ntoa (p
->u
.prefix4
));
81 /* Join to the OSPF ALL Designated ROUTERS multicast group. */
83 ospf_if_add_alldrouters (struct ospf
*top
, struct prefix
*p
, unsigned int
88 ret
= setsockopt_multicast_ipv4 (top
->fd
, IP_ADD_MEMBERSHIP
,
89 p
->u
.prefix4
, htonl (OSPF_ALLDROUTERS
),
92 zlog_warn ("can't setsockopt IP_ADD_MEMBERSHIP (AllDRouters): %s",
95 zlog_info ("interface %s join AllDRouters Multicast group.",
96 inet_ntoa (p
->u
.prefix4
));
102 ospf_if_drop_alldrouters (struct ospf
*top
, struct prefix
*p
, unsigned int
107 ret
= setsockopt_multicast_ipv4 (top
->fd
, IP_DROP_MEMBERSHIP
,
108 p
->u
.prefix4
, htonl (OSPF_ALLDROUTERS
),
111 zlog_warn ("can't setsockopt IP_DROP_MEMBERSHIP (AllDRouters): %s",
114 zlog_info ("interface %s leave AllDRouters Multicast group.",
115 inet_ntoa (p
->u
.prefix4
));
121 ospf_if_ipmulticast (struct ospf
*top
, struct prefix
*p
, unsigned int ifindex
)
129 /* Prevent receiving self-origined multicast packets. */
130 ret
= setsockopt (top
->fd
, IPPROTO_IP
, IP_MULTICAST_LOOP
, (void *)&val
, len
);
132 zlog_warn ("can't setsockopt IP_MULTICAST_LOOP(0): %s", strerror (errno
));
134 /* Explicitly set multicast ttl to 1 -- endo. */
136 ret
= setsockopt (top
->fd
, IPPROTO_IP
, IP_MULTICAST_TTL
, (void *)&val
, len
);
138 zlog_warn ("can't setsockopt IP_MULTICAST_TTL(1): %s", strerror (errno
));
140 ret
= setsockopt_multicast_ipv4 (top
->fd
, IP_MULTICAST_IF
,
141 p
->u
.prefix4
, 0, ifindex
);
143 zlog_warn ("can't setsockopt IP_MULTICAST_IF: %s", strerror (errno
));
149 ospf_sock_init (void)
152 int ret
, tos
, hincl
= 1;
154 ospf_sock
= socket (AF_INET
, SOCK_RAW
, IPPROTO_OSPFIGP
);
157 zlog_warn ("ospf_read_sock_init: socket: %s", strerror (errno
));
161 /* Set precedence field. */
162 #ifdef IPTOS_PREC_INTERNETCONTROL
163 tos
= IPTOS_PREC_INTERNETCONTROL
;
164 ret
= setsockopt (ospf_sock
, IPPROTO_IP
, IP_TOS
,
165 (char *) &tos
, sizeof (int));
168 zlog_warn ("can't set sockopt IP_TOS %d to socket %d", tos
, ospf_sock
);
169 close (ospf_sock
); /* Prevent sd leak. */
172 #endif /* IPTOS_PREC_INTERNETCONTROL */
174 /* we will include IP header with packet */
175 ret
= setsockopt (ospf_sock
, IPPROTO_IP
, IP_HDRINCL
, &hincl
, sizeof (hincl
));
177 zlog_warn ("Can't set IP_HDRINCL option");
179 #if defined (IP_PKTINFO)
180 ret
= setsockopt (ospf_sock
, IPPROTO_IP
, IP_PKTINFO
, &hincl
, sizeof (hincl
));
182 zlog_warn ("Can't set IP_PKTINFO option");
183 #elif defined (IP_RECVIF)
184 ret
= setsockopt (ospf_sock
, IPPROTO_IP
, IP_RECVIF
, &hincl
, sizeof (hincl
));
186 zlog_warn ("Can't set IP_RECVIF option");
188 #warning "cannot be able to receive link information on this OS"