1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* The mrouted program is covered by the license in the accompanying file
|
|
|
|
* named "LICENSE". Use of the mrouted program represents acceptance of
|
|
|
|
* the terms and conditions listed in that file.
|
|
|
|
*
|
|
|
|
* The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
|
|
|
|
* Leland Stanford Junior University.
|
|
|
|
*
|
|
|
|
*
|
1997-02-22 16:15:28 +00:00
|
|
|
* $Id$
|
1994-09-08 00:26:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Exported variables.
|
|
|
|
*/
|
1995-06-28 17:58:49 +00:00
|
|
|
char *recv_buf; /* input packet buffer */
|
|
|
|
char *send_buf; /* output packet buffer */
|
1994-09-08 00:26:13 +00:00
|
|
|
int igmp_socket; /* socket for all network I/O */
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 allhosts_group; /* All hosts addr in net order */
|
|
|
|
u_int32 allrtrs_group; /* All-Routers " in net order */
|
|
|
|
u_int32 dvmrp_group; /* DVMRP grp addr in net order */
|
|
|
|
u_int32 dvmrp_genid; /* IGMP generation id */
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1996-11-11 03:50:15 +00:00
|
|
|
/*
|
|
|
|
* Private variables
|
|
|
|
*/
|
|
|
|
static char router_alert[4]; /* Router Alert IP Option */
|
|
|
|
#ifndef IPOPT_RA
|
|
|
|
#define IPOPT_RA 148
|
|
|
|
#endif
|
|
|
|
#ifdef SUNOS5
|
|
|
|
static char no_op[4]; /* Null IP Option */
|
|
|
|
static int ip_addlen = 0; /* Workaround for Option bug #2*/
|
|
|
|
#endif
|
|
|
|
#define SEND_RA(x) (((x) == IGMP_MEMBERSHIP_QUERY) || \
|
|
|
|
((x) == IGMP_V1_MEMBERSHIP_REPORT) || \
|
|
|
|
((x) == IGMP_V2_MEMBERSHIP_REPORT) || \
|
|
|
|
((x) == IGMP_V2_LEAVE_GROUP) || \
|
|
|
|
((x) == IGMP_MTRACE))
|
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
/*
|
|
|
|
* Local function definitions.
|
|
|
|
*/
|
|
|
|
/* u_char promoted to u_int */
|
|
|
|
static char * packet_kind __P((u_int type, u_int code));
|
|
|
|
static int igmp_log_level __P((u_int type, u_int code));
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
/*
|
|
|
|
* Open and initialize the igmp socket, and fill in the non-changing
|
|
|
|
* IP header fields in the output packet buffer.
|
|
|
|
*/
|
1995-06-28 17:58:49 +00:00
|
|
|
void
|
|
|
|
init_igmp()
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
struct ip *ip;
|
1996-11-11 03:50:15 +00:00
|
|
|
#ifdef SUNOS5
|
|
|
|
u_int32 localhost = htonl(0x7f000001);
|
|
|
|
#endif
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
recv_buf = malloc(RECV_BUF_SIZE);
|
|
|
|
send_buf = malloc(RECV_BUF_SIZE);
|
|
|
|
|
|
|
|
if ((igmp_socket = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP)) < 0)
|
1994-09-08 00:26:13 +00:00
|
|
|
log(LOG_ERR, errno, "IGMP socket");
|
|
|
|
|
|
|
|
k_hdr_include(TRUE); /* include IP header when sending */
|
|
|
|
k_set_rcvbuf(48*1024); /* lots of input buffering */
|
|
|
|
k_set_ttl(1); /* restrict multicasts to one hop */
|
|
|
|
k_set_loop(FALSE); /* disable multicast loopback */
|
|
|
|
|
|
|
|
ip = (struct ip *)send_buf;
|
1994-09-08 02:51:37 +00:00
|
|
|
ip->ip_hl = sizeof(struct ip) >> 2;
|
|
|
|
ip->ip_v = IPVERSION;
|
1994-09-08 00:26:13 +00:00
|
|
|
ip->ip_tos = 0;
|
|
|
|
ip->ip_off = 0;
|
|
|
|
ip->ip_p = IPPROTO_IGMP;
|
|
|
|
ip->ip_ttl = MAXTTL; /* applies to unicasts only */
|
|
|
|
|
|
|
|
allhosts_group = htonl(INADDR_ALLHOSTS_GROUP);
|
|
|
|
dvmrp_group = htonl(INADDR_DVMRP_GROUP);
|
1995-06-13 18:05:16 +00:00
|
|
|
allrtrs_group = htonl(INADDR_ALLRTRS_GROUP);
|
1996-11-11 03:50:15 +00:00
|
|
|
|
|
|
|
router_alert[0] = IPOPT_RA; /* Router Alert */
|
|
|
|
router_alert[1] = 4; /* 4 bytes */
|
|
|
|
router_alert[2] = 0;
|
|
|
|
router_alert[3] = 0;
|
|
|
|
|
|
|
|
#ifdef SUNOS5
|
|
|
|
no_op[0] = IPOPT_NOP;
|
|
|
|
no_op[1] = IPOPT_NOP;
|
|
|
|
no_op[2] = IPOPT_NOP;
|
|
|
|
no_op[3] = IPOPT_NOP;
|
|
|
|
|
|
|
|
setsockopt(igmp_socket, IPPROTO_IP, IP_OPTIONS, no_op, sizeof(no_op));
|
|
|
|
/*
|
|
|
|
* Check if the kernel adds the options length to the packet
|
|
|
|
* length. Send myself an IGMP packet of type 0 (illegal),
|
|
|
|
* with 4 IPOPT_NOP options, my PID (for collision detection)
|
|
|
|
* and 4 bytes of zero (so that the checksum works whether
|
|
|
|
* the 4 bytes of zero get truncated or not).
|
|
|
|
*/
|
|
|
|
bzero(send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN, 8);
|
|
|
|
*(int *)(send_buf + MIN_IP_HEADER_LEN + IGMP_MINLEN) = getpid();
|
|
|
|
send_igmp(localhost, localhost, 0, 0, 0, 8);
|
|
|
|
while (1) {
|
|
|
|
int recvlen, dummy = 0;
|
|
|
|
|
|
|
|
recvlen = recvfrom(igmp_socket, recv_buf, RECV_BUF_SIZE,
|
|
|
|
0, NULL, &dummy);
|
|
|
|
/* 8 == 4 bytes of options and 4 bytes of PID */
|
|
|
|
if (recvlen >= MIN_IP_HEADER_LEN + IGMP_MINLEN + 8) {
|
|
|
|
struct ip *ip = (struct ip *)recv_buf;
|
|
|
|
struct igmp *igmp;
|
|
|
|
int *p;
|
|
|
|
|
|
|
|
if (ip->ip_hl != 6 ||
|
|
|
|
ip->ip_p != IPPROTO_IGMP ||
|
|
|
|
ip->ip_src.s_addr != localhost ||
|
|
|
|
ip->ip_dst.s_addr != localhost)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
igmp = (struct igmp *)(recv_buf + (ip->ip_hl << 2));
|
|
|
|
if (igmp->igmp_group.s_addr != 0)
|
|
|
|
continue;
|
|
|
|
if (igmp->igmp_type != 0 || igmp->igmp_code != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
p = (int *)((char *)igmp + IGMP_MINLEN);
|
|
|
|
if (*p != getpid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ip->ip_len == IGMP_MINLEN + 4)
|
|
|
|
ip_addlen = 4;
|
|
|
|
else if (ip->ip_len == IGMP_MINLEN + 8)
|
|
|
|
ip_addlen = 0;
|
|
|
|
else
|
|
|
|
log(LOG_ERR, 0, "while checking for Solaris bug: Sent %d bytes and got back %d!", IGMP_MINLEN + 8, ip->ip_len);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define PIM_QUERY 0
|
|
|
|
#define PIM_REGISTER 1
|
|
|
|
#define PIM_REGISTER_STOP 2
|
|
|
|
#define PIM_JOIN_PRUNE 3
|
|
|
|
#define PIM_RP_REACHABLE 4
|
|
|
|
#define PIM_ASSERT 5
|
|
|
|
#define PIM_GRAFT 6
|
|
|
|
#define PIM_GRAFT_ACK 7
|
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
static char *
|
|
|
|
packet_kind(type, code)
|
|
|
|
u_int type, code;
|
1994-09-08 00:26:13 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case IGMP_HOST_MEMBERSHIP_QUERY: return "membership query ";
|
1996-11-11 03:50:15 +00:00
|
|
|
case IGMP_HOST_MEMBERSHIP_REPORT: return "V1 member report ";
|
|
|
|
case IGMP_HOST_NEW_MEMBERSHIP_REPORT: return "V2 member report ";
|
1995-06-13 18:05:16 +00:00
|
|
|
case IGMP_HOST_LEAVE_MESSAGE: return "leave message ";
|
1994-09-08 00:26:13 +00:00
|
|
|
case IGMP_DVMRP:
|
|
|
|
switch (code) {
|
|
|
|
case DVMRP_PROBE: return "neighbor probe ";
|
|
|
|
case DVMRP_REPORT: return "route report ";
|
|
|
|
case DVMRP_ASK_NEIGHBORS: return "neighbor request ";
|
|
|
|
case DVMRP_NEIGHBORS: return "neighbor list ";
|
|
|
|
case DVMRP_ASK_NEIGHBORS2: return "neighbor request 2";
|
|
|
|
case DVMRP_NEIGHBORS2: return "neighbor list 2 ";
|
1995-06-13 18:05:16 +00:00
|
|
|
case DVMRP_PRUNE: return "prune message ";
|
|
|
|
case DVMRP_GRAFT: return "graft message ";
|
1994-09-08 00:26:13 +00:00
|
|
|
case DVMRP_GRAFT_ACK: return "graft message ack ";
|
1996-01-06 21:10:30 +00:00
|
|
|
case DVMRP_INFO_REQUEST: return "info request ";
|
|
|
|
case DVMRP_INFO_REPLY: return "info reply ";
|
1994-09-08 00:26:13 +00:00
|
|
|
default: return "unknown DVMRP msg ";
|
|
|
|
}
|
1995-06-13 18:05:16 +00:00
|
|
|
case IGMP_PIM:
|
1994-09-08 00:26:13 +00:00
|
|
|
switch (code) {
|
|
|
|
case PIM_QUERY: return "PIM Router-Query ";
|
|
|
|
case PIM_REGISTER: return "PIM Register ";
|
|
|
|
case PIM_REGISTER_STOP: return "PIM Register-Stop ";
|
|
|
|
case PIM_JOIN_PRUNE: return "PIM Join/Prune ";
|
|
|
|
case PIM_RP_REACHABLE: return "PIM RP-Reachable ";
|
|
|
|
case PIM_ASSERT: return "PIM Assert ";
|
|
|
|
case PIM_GRAFT: return "PIM Graft ";
|
|
|
|
case PIM_GRAFT_ACK: return "PIM Graft-Ack ";
|
|
|
|
default: return "unknown PIM msg ";
|
|
|
|
}
|
|
|
|
case IGMP_MTRACE: return "IGMP trace query ";
|
|
|
|
case IGMP_MTRACE_RESP: return "IGMP trace reply ";
|
|
|
|
default: return "unknown IGMP msg ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process a newly received IGMP packet that is sitting in the input
|
|
|
|
* packet buffer.
|
|
|
|
*/
|
1995-06-28 17:58:49 +00:00
|
|
|
void
|
|
|
|
accept_igmp(recvlen)
|
1994-09-08 00:26:13 +00:00
|
|
|
int recvlen;
|
|
|
|
{
|
1995-06-13 18:05:16 +00:00
|
|
|
register u_int32 src, dst, group;
|
1994-09-08 00:26:13 +00:00
|
|
|
struct ip *ip;
|
|
|
|
struct igmp *igmp;
|
|
|
|
int ipdatalen, iphdrlen, igmpdatalen;
|
|
|
|
|
|
|
|
if (recvlen < sizeof(struct ip)) {
|
|
|
|
log(LOG_WARNING, 0,
|
|
|
|
"received packet too short (%u bytes) for IP header", recvlen);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ip = (struct ip *)recv_buf;
|
|
|
|
src = ip->ip_src.s_addr;
|
|
|
|
dst = ip->ip_dst.s_addr;
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
/*
|
1994-09-08 00:26:13 +00:00
|
|
|
* this is most likely a message from the kernel indicating that
|
1995-06-13 18:05:16 +00:00
|
|
|
* a new src grp pair message has arrived and so, it would be
|
1994-09-08 00:26:13 +00:00
|
|
|
* necessary to install a route into the kernel for this.
|
|
|
|
*/
|
|
|
|
if (ip->ip_p == 0) {
|
1995-05-16 00:28:50 +00:00
|
|
|
if (src == 0 || dst == 0)
|
1994-09-08 00:26:13 +00:00
|
|
|
log(LOG_WARNING, 0, "kernel request not accurate");
|
|
|
|
else
|
|
|
|
add_table_entry(src, dst);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
iphdrlen = ip->ip_hl << 2;
|
|
|
|
ipdatalen = ip->ip_len;
|
|
|
|
if (iphdrlen + ipdatalen != recvlen) {
|
|
|
|
log(LOG_WARNING, 0,
|
1996-01-06 21:10:30 +00:00
|
|
|
"received packet from %s shorter (%u bytes) than hdr+data length (%u+%u)",
|
|
|
|
inet_fmt(src, s1), recvlen, iphdrlen, ipdatalen);
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
igmp = (struct igmp *)(recv_buf + iphdrlen);
|
|
|
|
group = igmp->igmp_group.s_addr;
|
|
|
|
igmpdatalen = ipdatalen - IGMP_MINLEN;
|
|
|
|
if (igmpdatalen < 0) {
|
|
|
|
log(LOG_WARNING, 0,
|
|
|
|
"received IP data field too short (%u bytes) for IGMP, from %s",
|
|
|
|
ipdatalen, inet_fmt(src, s1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
log(LOG_DEBUG, 0, "RECV %s from %-15s to %s",
|
|
|
|
packet_kind(igmp->igmp_type, igmp->igmp_code),
|
|
|
|
inet_fmt(src, s1), inet_fmt(dst, s2));
|
|
|
|
|
|
|
|
switch (igmp->igmp_type) {
|
|
|
|
|
|
|
|
case IGMP_HOST_MEMBERSHIP_QUERY:
|
1995-06-13 18:05:16 +00:00
|
|
|
accept_membership_query(src, dst, group, igmp->igmp_code);
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case IGMP_HOST_MEMBERSHIP_REPORT:
|
|
|
|
case IGMP_HOST_NEW_MEMBERSHIP_REPORT:
|
1995-06-13 18:05:16 +00:00
|
|
|
accept_group_report(src, dst, group, igmp->igmp_type);
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
1995-06-13 18:05:16 +00:00
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
case IGMP_HOST_LEAVE_MESSAGE:
|
1995-06-13 18:05:16 +00:00
|
|
|
accept_leave_message(src, dst, group);
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case IGMP_DVMRP:
|
1995-06-13 18:05:16 +00:00
|
|
|
group = ntohl(group);
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
switch (igmp->igmp_code) {
|
1994-09-08 00:26:13 +00:00
|
|
|
case DVMRP_PROBE:
|
|
|
|
accept_probe(src, dst,
|
1995-06-13 18:05:16 +00:00
|
|
|
(char *)(igmp+1), igmpdatalen, group);
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case DVMRP_REPORT:
|
|
|
|
accept_report(src, dst,
|
1995-06-13 18:05:16 +00:00
|
|
|
(char *)(igmp+1), igmpdatalen, group);
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case DVMRP_ASK_NEIGHBORS:
|
|
|
|
accept_neighbor_request(src, dst);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case DVMRP_ASK_NEIGHBORS2:
|
|
|
|
accept_neighbor_request2(src, dst);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case DVMRP_NEIGHBORS:
|
1995-06-28 17:58:49 +00:00
|
|
|
accept_neighbors(src, dst, (u_char *)(igmp+1), igmpdatalen,
|
1995-06-13 18:05:16 +00:00
|
|
|
group);
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case DVMRP_NEIGHBORS2:
|
1995-06-28 17:58:49 +00:00
|
|
|
accept_neighbors2(src, dst, (u_char *)(igmp+1), igmpdatalen,
|
1995-06-13 18:05:16 +00:00
|
|
|
group);
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case DVMRP_PRUNE:
|
|
|
|
accept_prune(src, dst, (char *)(igmp+1), igmpdatalen);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case DVMRP_GRAFT:
|
|
|
|
accept_graft(src, dst, (char *)(igmp+1), igmpdatalen);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case DVMRP_GRAFT_ACK:
|
|
|
|
accept_g_ack(src, dst, (char *)(igmp+1), igmpdatalen);
|
|
|
|
return;
|
|
|
|
|
1996-01-06 21:10:30 +00:00
|
|
|
case DVMRP_INFO_REQUEST:
|
|
|
|
accept_info_request(src, dst, (char *)(igmp+1),
|
|
|
|
igmpdatalen);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case DVMRP_INFO_REPLY:
|
|
|
|
accept_info_reply(src, dst, (char *)(igmp+1), igmpdatalen);
|
|
|
|
return;
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
default:
|
|
|
|
log(LOG_INFO, 0,
|
|
|
|
"ignoring unknown DVMRP message code %u from %s to %s",
|
|
|
|
igmp->igmp_code, inet_fmt(src, s1),
|
|
|
|
inet_fmt(dst, s2));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
case IGMP_PIM:
|
1994-09-08 00:26:13 +00:00
|
|
|
return;
|
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
case IGMP_MTRACE_RESP:
|
|
|
|
return;
|
|
|
|
|
1994-09-08 00:26:13 +00:00
|
|
|
case IGMP_MTRACE:
|
1995-06-13 18:05:16 +00:00
|
|
|
accept_mtrace(src, dst, group, (char *)(igmp+1),
|
1994-09-08 00:26:13 +00:00
|
|
|
igmp->igmp_code, igmpdatalen);
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
log(LOG_INFO, 0,
|
1995-06-13 18:05:16 +00:00
|
|
|
"ignoring unknown IGMP message type %x from %s to %s",
|
1994-09-08 00:26:13 +00:00
|
|
|
igmp->igmp_type, inet_fmt(src, s1),
|
|
|
|
inet_fmt(dst, s2));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-06-28 17:58:49 +00:00
|
|
|
/*
|
|
|
|
* Some IGMP messages are more important than others. This routine
|
|
|
|
* determines the logging level at which to log a send error (often
|
|
|
|
* "No route to host"). This is important when there is asymmetric
|
|
|
|
* reachability and someone is trying to, i.e., mrinfo me periodically.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
igmp_log_level(type, code)
|
|
|
|
u_int type, code;
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case IGMP_MTRACE_RESP:
|
|
|
|
return LOG_INFO;
|
|
|
|
|
|
|
|
case IGMP_DVMRP:
|
|
|
|
switch (code) {
|
|
|
|
case DVMRP_NEIGHBORS:
|
|
|
|
case DVMRP_NEIGHBORS2:
|
|
|
|
return LOG_INFO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return LOG_WARNING;
|
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct an IGMP message in the output packet buffer. The caller may
|
|
|
|
* have already placed data in that buffer, of length 'datalen'. Then send
|
|
|
|
* the message from the interface with IP address 'src' to destination 'dst'.
|
|
|
|
*/
|
1995-06-13 18:05:16 +00:00
|
|
|
void
|
|
|
|
send_igmp(src, dst, type, code, group, datalen)
|
|
|
|
u_int32 src, dst;
|
1994-09-08 00:26:13 +00:00
|
|
|
int type, code;
|
1995-06-13 18:05:16 +00:00
|
|
|
u_int32 group;
|
1994-09-08 00:26:13 +00:00
|
|
|
int datalen;
|
|
|
|
{
|
1996-01-06 21:10:30 +00:00
|
|
|
struct sockaddr_in sdst;
|
1994-09-08 00:26:13 +00:00
|
|
|
struct ip *ip;
|
|
|
|
struct igmp *igmp;
|
1996-11-11 03:50:15 +00:00
|
|
|
int setloop = 0;
|
|
|
|
static int raset = 0;
|
|
|
|
int sendra = 0;
|
|
|
|
int sendlen;
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
ip = (struct ip *)send_buf;
|
|
|
|
ip->ip_src.s_addr = src;
|
|
|
|
ip->ip_dst.s_addr = dst;
|
|
|
|
ip->ip_len = MIN_IP_HEADER_LEN + IGMP_MINLEN + datalen;
|
1996-11-11 03:50:15 +00:00
|
|
|
sendlen = ip->ip_len;
|
|
|
|
#ifdef SUNOS5
|
|
|
|
ip->ip_len += ip_addlen;
|
|
|
|
#endif
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
igmp = (struct igmp *)(send_buf + MIN_IP_HEADER_LEN);
|
|
|
|
igmp->igmp_type = type;
|
|
|
|
igmp->igmp_code = code;
|
|
|
|
igmp->igmp_group.s_addr = group;
|
|
|
|
igmp->igmp_cksum = 0;
|
|
|
|
igmp->igmp_cksum = inet_cksum((u_short *)igmp,
|
|
|
|
IGMP_MINLEN + datalen);
|
|
|
|
|
1996-01-06 21:10:30 +00:00
|
|
|
if (IN_MULTICAST(ntohl(dst))) {
|
|
|
|
k_set_if(src);
|
1996-01-29 16:04:20 +00:00
|
|
|
if (type != IGMP_DVMRP || dst == allhosts_group) {
|
1996-01-06 21:10:30 +00:00
|
|
|
setloop = 1;
|
1995-10-07 03:48:44 +00:00
|
|
|
k_set_loop(TRUE);
|
1996-01-06 21:10:30 +00:00
|
|
|
}
|
1996-11-11 03:50:15 +00:00
|
|
|
if (SEND_RA(type))
|
|
|
|
sendra = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendra && !raset) {
|
|
|
|
setsockopt(igmp_socket, IPPROTO_IP, IP_OPTIONS,
|
|
|
|
router_alert, sizeof(router_alert));
|
|
|
|
raset = 1;
|
|
|
|
} else if (!sendra && raset) {
|
|
|
|
#ifdef SUNOS5
|
|
|
|
/*
|
|
|
|
* SunOS5 < 5.6 cannot properly reset the IP_OPTIONS "socket"
|
|
|
|
* option. Instead, set up a string of 4 no-op's.
|
|
|
|
*/
|
|
|
|
setsockopt(igmp_socket, IPPROTO_IP, IP_OPTIONS,
|
|
|
|
no_op, sizeof(no_op));
|
|
|
|
#else
|
|
|
|
setsockopt(igmp_socket, IPPROTO_IP, IP_OPTIONS,
|
|
|
|
NULL, 0);
|
|
|
|
#endif
|
|
|
|
raset = 0;
|
1996-01-06 21:10:30 +00:00
|
|
|
}
|
1994-09-08 00:26:13 +00:00
|
|
|
|
1995-06-13 18:05:16 +00:00
|
|
|
bzero(&sdst, sizeof(sdst));
|
|
|
|
sdst.sin_family = AF_INET;
|
|
|
|
#if (defined(BSD) && (BSD >= 199103))
|
|
|
|
sdst.sin_len = sizeof(sdst);
|
|
|
|
#endif
|
1994-09-08 00:26:13 +00:00
|
|
|
sdst.sin_addr.s_addr = dst;
|
1996-11-11 03:50:15 +00:00
|
|
|
if (sendto(igmp_socket, send_buf, sendlen, 0,
|
1994-09-08 00:26:13 +00:00
|
|
|
(struct sockaddr *)&sdst, sizeof(sdst)) < 0) {
|
1995-05-16 00:28:50 +00:00
|
|
|
if (errno == ENETDOWN)
|
|
|
|
check_vif_state();
|
|
|
|
else
|
1995-06-28 17:58:49 +00:00
|
|
|
log(igmp_log_level(type, code), errno,
|
1995-05-16 00:28:50 +00:00
|
|
|
"sendto to %s on %s",
|
|
|
|
inet_fmt(dst, s1), inet_fmt(src, s2));
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|
|
|
|
|
1996-01-06 21:10:30 +00:00
|
|
|
if (setloop)
|
1995-10-07 03:48:44 +00:00
|
|
|
k_set_loop(FALSE);
|
1994-09-08 00:26:13 +00:00
|
|
|
|
|
|
|
log(LOG_DEBUG, 0, "SENT %s from %-15s to %s",
|
1996-11-11 03:50:15 +00:00
|
|
|
packet_kind(type, code), src == INADDR_ANY ? "INADDR_ANY" :
|
|
|
|
inet_fmt(src, s1), inet_fmt(dst, s2));
|
1994-09-08 00:26:13 +00:00
|
|
|
}
|