#ident "%Z%%M% %I% %E% SMI"
#include "defs.h"
void
supplyall(struct sockaddr_in6 *sin6, int rtstate, struct interface *skipif,
boolean_t splith)
{
struct interface *ifp;
for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) {
if ((ifp->int_flags & RIP6_IFF_UP) == 0)
continue;
if (ifp->int_flags & RIP6_IFF_NORTEXCH) {
if (tracing & OUTPUT_BIT) {
(void) fprintf(ftrace,
"Suppress sending RIPng response packet "
"on %s (no route exchange on interface)\n",
ifp->int_name);
(void) fflush(ftrace);
}
continue;
}
if (ifp->int_sock == -1)
continue;
if (ifp == skipif)
continue;
if (!IN6_IS_ADDR_LINKLOCAL(&ifp->int_addr))
continue;
supply(sin6, ifp, rtstate, splith);
}
}
static void
solicit(struct sockaddr_in6 *sin6, struct interface *ifp)
{
msg->rip6_cmd = RIPCMD6_REQUEST;
msg->rip6_vers = RIPVERSION6;
msg->rip6_nets[0].rip6_prefix = in6addr_any;
msg->rip6_nets[0].rip6_prefix_length = 0;
msg->rip6_nets[0].rip6_metric = HOPCNT_INFINITY;
sendpacket(sin6, ifp, sizeof (struct rip6), 0);
}
void
solicitall(struct sockaddr_in6 *sin6)
{
struct interface *ifp;
for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) {
if ((ifp->int_flags & RIP6_IFF_UP) == 0)
continue;
if (ifp->int_flags & RIP6_IFF_NORTEXCH) {
if (tracing & OUTPUT_BIT) {
(void) fprintf(ftrace,
"Suppress sending RIPng request packet "
"on %s (no route exchange on interface)\n",
ifp->int_name);
(void) fflush(ftrace);
}
continue;
}
if (ifp->int_sock == -1)
continue;
solicit(sin6, ifp);
}
}
void
sendpacket(struct sockaddr_in6 *sin6, struct interface *ifp, int size,
int flags)
{
if (sendto(ifp->int_sock, packet, size, flags,
(struct sockaddr *)sin6, sizeof (*sin6)) < 0) {
syslog(LOG_ERR, "sendpacket: sendto: %m");
return;
}
TRACE_OUTPUT(ifp, sin6, sizeof (struct rip6));
ifp->int_opackets++;
}
void
supply(struct sockaddr_in6 *sin6, struct interface *ifp, int rtstate,
boolean_t splith)
{
struct rt_entry *rt;
struct netinfo6 *n = msg->rip6_nets;
struct rthash *rh;
int size, i, maxsize;
uint8_t rtmetric;
msg->rip6_cmd = RIPCMD6_RESPONSE;
msg->rip6_vers = RIPVERSION6;
maxsize = ifp->int_mtu - sizeof (ip6_t) - sizeof (struct udphdr);
for (i = IPV6_ABITS; i >= 0; i--) {
if (net_hashes[i] == NULL)
continue;
for (rh = net_hashes[i]; rh < &net_hashes[i][ROUTEHASHSIZ];
rh++) {
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh;
rt = rt->rt_forw) {
if (IN6_IS_ADDR_LINKLOCAL(&rt->rt_dst))
continue;
if (IN6_IS_ADDR_UNSPECIFIED(&rt->rt_dst))
continue;
if (rt->rt_state & RTS_PRIVATE)
continue;
if (splith && rt->rt_ifp != NULL &&
strcmp(ifp->int_ifbase,
rt->rt_ifp->int_ifbase) == 0) {
if (dopoison)
rtmetric = HOPCNT_INFINITY;
else
continue;
} else {
rtmetric = rt->rt_metric;
}
if (rtstate != 0 &&
(rt->rt_state & rtstate) == 0)
continue;
size = (char *)n - packet;
if (size > maxsize - sizeof (struct netinfo6)) {
sendpacket(sin6, ifp, size, 0);
TRACE_OUTPUT(ifp, sin6, size);
n = msg->rip6_nets;
}
n->rip6_prefix = rt->rt_dst;
n->rip6_route_tag = rt->rt_tag;
n->rip6_prefix_length = rt->rt_prefix_length;
n->rip6_metric = min(rtmetric, HOPCNT_INFINITY);
n++;
}
}
}
if (n != msg->rip6_nets) {
size = (char *)n - packet;
sendpacket(sin6, ifp, size, 0);
TRACE_OUTPUT(ifp, sin6, size);
}
}