struct in_addr addr;
struct prefix_ipv4 *p;
+ if (connected != NULL)
+ {
if (if_pointopoint)
p = (struct prefix_ipv4 *) connected->destination;
else
p = (struct prefix_ipv4 *) connected->address;
-
addr = p->prefix;
+ }
+ else
+ {
+ addr.s_addr = INADDR_ANY;
+ }
-
- if (setsockopt_multicast_ipv4 (sock, IP_MULTICAST_IF,
- addr, 0, 0) < 0)
+ if (setsockopt_multicast_ipv4 (sock, IP_MULTICAST_IF, addr, 0, 0) < 0)
{
zlog_warn ("Can't setsockopt IP_MULTICAST_IF to fd %d", sock);
return;
else
from.sin_port = htons (RIP_PORT_DEFAULT);
- /* Address shoud be any address. */
+ /* Address should be any address. */
from.sin_family = AF_INET;
+ if (connected)
addr = ((struct prefix_ipv4 *) connected->address)->prefix;
from.sin_addr = addr;
#ifdef HAVE_SIN_LEN
if (ripd_privs.change (ZPRIVS_RAISE))
zlog_err ("rip_interface_multicast_set: could not raise privs");
- bind (sock, NULL, 0); /* unbind any previous association */
ret = bind (sock, (struct sockaddr *) & from, sizeof (struct sockaddr_in));
if (ret < 0)
{
if (IS_RIP_DEBUG_EVENT)
zlog_info ("multicast request on %s", ifp->name);
- rip_request_send (NULL, ifp, version);
+ rip_request_send (NULL, ifp, version, NULL);
return;
}
if (IS_RIP_DEBUG_EVENT)
zlog_info ("SEND request to %s", inet_ntoa (to.sin_addr));
- rip_request_send (&to, ifp, version);
+ rip_request_send (&to, ifp, version, connected);
}
}
}
to.sin_port = htons (RIP_PORT_DEFAULT);
to.sin_addr = addr;
- rip_request_send (&to, NULL, rip->version_send);
+ rip_request_send (&to, NULL, rip->version_send, NULL);
}
/* Request routes at all interfaces. */
void rip_output_process (struct interface *, struct prefix *,
struct sockaddr_in *, int, u_char,
- struct prefix_ipv4 *);
+ struct connected *, struct prefix_ipv4 *);
/* RIP output routes type. */
enum
/* RIP packet send to destination address. */
int
rip_send_packet (caddr_t buf, int size, struct sockaddr_in *to,
- struct interface *ifp)
+ struct interface *ifp, struct connected *connected)
{
- int ret;
+ int ret, send_sock;
struct sockaddr_in sin;
+ if (IS_RIP_DEBUG_PACKET)
+ {
+ char dst[20];
+ if (to)
+ {
+ strcpy(dst, inet_ntoa(to->sin_addr));
+ }
+ else
+ {
+ sin.sin_addr.s_addr = htonl (INADDR_RIP_GROUP);
+ strcpy(dst, inet_ntoa(sin.sin_addr));
+ }
+ zlog_info("rip_send_packet %s > %s (%s)",
+ inet_ntoa(connected->address->u.prefix4), dst, ifp->name);
+ }
+ if (connected->flags & ZEBRA_IFA_SECONDARY)
+ {
+ /*
+ * ZEBRA_IFA_SECONDARY is set on linux when an interface is configured
+ * with multiple addresses on the same subnet: the first address
+ * on the subnet is configured "primary", and all subsequent addresses
+ * on that subnet are treated as "secondary" addresses.
+ * In order to avoid routing-table bloat on other rip listeners,
+ * we do not send out RIP packets with ZEBRA_IFA_SECONDARY source addrs.
+ * XXX Since Linux is the only system for which the ZEBRA_IFA_SECONDARY
+ * flag is set, we would end up sending a packet for a "secondary"
+ * source address on non-linux systems.
+ */
+ if (IS_RIP_DEBUG_PACKET)
+ zlog_info("duplicate dropped");
+ return 0;
+ }
+
/* Make destination address. */
memset (&sin, 0, sizeof (struct sockaddr_in));
sin.sin_family = AF_INET;
{
sin.sin_port = to->sin_port;
sin.sin_addr = to->sin_addr;
+ send_sock = rip->sock;
}
else
{
sin.sin_port = htons (RIP_PORT_DEFAULT);
sin.sin_addr.s_addr = htonl (INADDR_RIP_GROUP);
- /* caller has set multicast interface */
-
+ /*
+ * we have to open a new socket for each packet because this
+ * is the most portable way to bind to a different source
+ * ipv4 address for each packet.
+ */
+ send_sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (send_sock < 0)
+ {
+ zlog_warn("rip_send_packet could not create socket %s",
+ strerror(errno));
+ return -1;
+ }
+ sockopt_broadcast (send_sock);
+ sockopt_reuseaddr (send_sock);
+ sockopt_reuseport (send_sock);
+#ifdef RIP_RECVMSG
+ setsockopt_pktinfo (send_sock);
+#endif /* RIP_RECVMSG */
+ rip_interface_multicast_set(send_sock, connected, if_is_pointopoint(ifp));
}
- ret = sendto (rip->sock, buf, size, 0, (struct sockaddr *)&sin,
+ ret = sendto (send_sock, buf, size, 0, (struct sockaddr *)&sin,
sizeof (struct sockaddr_in));
if (IS_RIP_DEBUG_EVENT)
if (ret < 0)
zlog_warn ("can't send packet : %s", strerror (errno));
+ if (!to)
+ close(send_sock);
+
return ret;
}
/* All route with split horizon */
rip_output_process (ifp, NULL, from, rip_all_route, packet->version,
- &saddr);
+ NULL, &saddr);
}
else
{
}
packet->command = RIP_RESPONSE;
- rip_send_packet ((caddr_t) packet, size, from, ifp);
+ rip_send_packet ((caddr_t) packet, size, from, ifp, NULL);
}
rip_global_queries++;
}
void
rip_output_process (struct interface *ifp, struct prefix *ifaddr,
struct sockaddr_in *to, int route_type, u_char version,
- struct prefix_ipv4 *saddr)
+ struct connected *connected, struct prefix_ipv4 *saddr)
{
int ret;
struct stream *s;
rip_auth_md5_set (s, ifp);
ret = rip_send_packet (STREAM_DATA (s), stream_get_endp (s),
- to, ifp);
+ to, ifp, connected);
if (ret >= 0 && IS_RIP_DEBUG_SEND)
rip_packet_dump ((struct rip_packet *)STREAM_DATA (s),
if (version == RIPv2 && ri->auth_type == RIP_AUTH_MD5)
rip_auth_md5_set (s, ifp);
- ret = rip_send_packet (STREAM_DATA (s), stream_get_endp (s), to, ifp);
+ ret = rip_send_packet (STREAM_DATA (s), stream_get_endp (s), to, ifp,
+ connected);
if (ret >= 0 && IS_RIP_DEBUG_SEND)
rip_packet_dump ((struct rip_packet *)STREAM_DATA (s),
/* Send RIP packet to the interface. */
void
rip_update_interface (struct interface *ifp, u_char version, int route_type,
- struct prefix_ipv4 *saddr)
+ struct connected *sconn)
{
struct prefix_ipv4 *p;
struct connected *connected;
listnode node;
struct sockaddr_in to;
+ struct prefix_ipv4 *saddr = (struct prefix_ipv4 *) sconn->address;
/* When RIP version is 2 and multicast enable interface. */
if (version == RIPv2 && if_is_multicast (ifp))
zlog_info ("multicast announce on %s ", ifp->name);
rip_output_process (ifp, NULL, NULL, route_type, rip->version_send,
- saddr);
+ sconn, saddr);
return;
}
inet_ntoa (to.sin_addr), ifp->name);
rip_output_process (ifp, connected->address, &to, route_type,
- rip->version_send, saddr);
+ rip->version_send, connected, saddr);
}
}
}
LIST_LOOP(ifp->connected, connected, ifnode)
{
struct prefix_ipv4 *ifaddr;
-
-
- /* If there is no version configuration in the interface,
- use rip's version setting. */
+ int done = 0;
+ /*
+ * If there is no version configuration in the interface,
+ * use rip's version setting.
+ */
int vsend = ((ri->ri_send == RI_RIP_UNSPEC) ?
rip->version_send : ri->ri_send);
if (ifaddr->family != AF_INET)
continue;
- rip_interface_multicast_set(rip->sock, connected,
- if_is_pointopoint(ifp));
- if (vsend & RIPv1)
- rip_update_interface (ifp, RIPv1, route_type, ifaddr);
- if (vsend & RIPv2)
- rip_update_interface (ifp, RIPv2, route_type, ifaddr);
+ if ((vsend & RIPv1) && !done)
+ rip_update_interface (ifp, RIPv1, route_type, connected);
+ if ((vsend & RIPv2) && if_is_multicast(ifp))
+ rip_update_interface (ifp, RIPv2, route_type, connected);
+ done = 1;
+ if (!(vsend & RIPv2) || !if_is_multicast(ifp))
+ break;
+
}
}
}
to.sin_port = htons (RIP_PORT_DEFAULT);
/* RIP version is rip's configuration. */
- rip_output_process (ifp, NULL, &to, route_type, rip->version_send, p);
+ rip_output_process (ifp, NULL, &to, route_type, rip->version_send,
+ NULL, p);
}
}
/* Sned RIP request to the destination. */
int
rip_request_send (struct sockaddr_in *to, struct interface *ifp,
- u_char version)
+ u_char version, struct connected *connected)
{
struct rte *rte;
struct rip_packet rip_packet;
listnode node;
- struct connected *connected;
memset (&rip_packet, 0, sizeof (rip_packet));
rte = rip_packet.rte;
rte->metric = htonl (RIP_METRIC_INFINITY);
+ if (connected)
+ {
+ /*
+ * connected is only sent for ripv1 case, or when
+ * interface does not support multicast. Caller loops
+ * over each connected address for this case.
+ */
+ if (rip_send_packet ((caddr_t) &rip_packet, sizeof (rip_packet),
+ to, ifp, connected) != sizeof (rip_packet))
+ return -1;
+ else
+ return sizeof (rip_packet);
+ }
+
/* send request on each connected network */
LIST_LOOP(ifp->connected, connected, node)
{
if (p->family != AF_INET)
continue;
- rip_interface_multicast_set(rip->sock, connected,
- if_is_pointopoint(ifp));
if (rip_send_packet ((caddr_t) &rip_packet, sizeof (rip_packet),
- to, ifp) != sizeof (rip_packet))
+ to, ifp, connected) != sizeof (rip_packet))
return -1;
}
return sizeof (rip_packet);