forked from Mirror/frr
2005-08-16 Paul Jakma <paul.jakma@sun.com>
* ripd.c: (general) Fix previous commit, broke multicast bind and hence setting of source port, which broke communication with non-borken ripd. Fix removes more stuff from rip_interface.c than it adds to ripd.c ;) (rip_create_socket) the to argument really is a from argument, rename it. Set the source port to RIP port unconditionally, it's required. (rip_send_packet) Set from address correctly for multicast. (rip_output_process) trivial: num can be BSS specified, rather than in body. * rip_interface.c: (rip_interface_multicast_set) strip out redundant stuff related to bind, which rip_create_socket does. Just make it set the multicast socket option, as per the interface concerned, no more.
This commit is contained in:
parent
60f0651c32
commit
2c61ae3782
|
@ -1,3 +1,20 @@
|
||||||
|
2005-08-16 Paul Jakma <paul.jakma@sun.com>
|
||||||
|
|
||||||
|
* ripd.c: (general) Fix previous commit, broke multicast bind and
|
||||||
|
hence setting of source port, which broke communication with
|
||||||
|
non-borken ripd. Fix removes more stuff from rip_interface.c
|
||||||
|
than it adds to ripd.c ;)
|
||||||
|
(rip_create_socket) the to argument really is a from argument,
|
||||||
|
rename it. Set the source port to RIP port unconditionally, it's
|
||||||
|
required.
|
||||||
|
(rip_send_packet) Set from address correctly for multicast.
|
||||||
|
(rip_output_process) trivial: num can be BSS specified, rather
|
||||||
|
than in body.
|
||||||
|
* rip_interface.c: (rip_interface_multicast_set) strip out
|
||||||
|
redundant stuff related to bind, which rip_create_socket does.
|
||||||
|
Just make it set the multicast socket option, as per the
|
||||||
|
interface concerned, no more.
|
||||||
|
|
||||||
2005-06-03 Paul Jakma <paul.jakma@sun.com>
|
2005-06-03 Paul Jakma <paul.jakma@sun.com>
|
||||||
|
|
||||||
* ripd.c: (rip_create_socket) move it up so rip_send_packet
|
* ripd.c: (rip_create_socket) move it up so rip_send_packet
|
||||||
|
|
|
@ -139,9 +139,6 @@ rip_interface_new ()
|
||||||
void
|
void
|
||||||
rip_interface_multicast_set (int sock, struct connected *connected)
|
rip_interface_multicast_set (int sock, struct connected *connected)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
struct servent *sp;
|
|
||||||
struct sockaddr_in from;
|
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
struct prefix_ipv4 *p;
|
struct prefix_ipv4 *p;
|
||||||
|
|
||||||
|
@ -161,43 +158,8 @@ rip_interface_multicast_set (int sock, struct connected *connected)
|
||||||
"source address %s for interface %s",
|
"source address %s for interface %s",
|
||||||
sock, inet_ntoa(addr),
|
sock, inet_ntoa(addr),
|
||||||
connected->ifp->name);
|
connected->ifp->name);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bind myself. */
|
|
||||||
memset (&from, 0, sizeof (struct sockaddr_in));
|
|
||||||
|
|
||||||
/* Set RIP port. */
|
|
||||||
sp = getservbyname ("router", "udp");
|
|
||||||
if (sp)
|
|
||||||
from.sin_port = sp->s_port;
|
|
||||||
else
|
|
||||||
from.sin_port = htons (RIP_PORT_DEFAULT);
|
|
||||||
|
|
||||||
/* Address should be any address. */
|
|
||||||
from.sin_family = AF_INET;
|
|
||||||
from.sin_addr = connected->address->u.prefix4;
|
|
||||||
#ifdef HAVE_SIN_LEN
|
|
||||||
from.sin_len = sizeof (struct sockaddr_in);
|
|
||||||
#endif /* HAVE_SIN_LEN */
|
|
||||||
|
|
||||||
if (ripd_privs.change (ZPRIVS_RAISE))
|
|
||||||
zlog_err ("rip_interface_multicast_set: could not raise privs");
|
|
||||||
|
|
||||||
ret = bind (sock, (struct sockaddr *) & from, sizeof (struct sockaddr_in));
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
zlog_warn ("Can't bind socket fd %d to %s port %d for "
|
|
||||||
"interface %s: %s",
|
|
||||||
sock,inet_ntoa(from.sin_addr),
|
|
||||||
(int)ntohs(from.sin_port),
|
|
||||||
connected->ifp->name,
|
|
||||||
safe_strerror (errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ripd_privs.change (ZPRIVS_LOWER))
|
|
||||||
zlog_err ("rip_interface_multicast_set: could not lower privs");
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
37
ripd/ripd.c
37
ripd/ripd.c
|
@ -1321,21 +1321,26 @@ rip_response_process (struct rip_packet *packet, int size,
|
||||||
|
|
||||||
/* Make socket for RIP protocol. */
|
/* Make socket for RIP protocol. */
|
||||||
static int
|
static int
|
||||||
rip_create_socket (struct sockaddr_in *to)
|
rip_create_socket (struct sockaddr_in *from)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int sock;
|
int sock;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
|
|
||||||
if (!to)
|
|
||||||
{
|
|
||||||
memset (&addr, 0, sizeof (struct sockaddr_in));
|
memset (&addr, 0, sizeof (struct sockaddr_in));
|
||||||
addr.sin_family = AF_INET;
|
|
||||||
addr.sin_port = htons (RIP_PORT_DEFAULT);
|
if (!from)
|
||||||
|
{
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = INADDR_ANY;
|
addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
#ifdef HAVE_SINLEN
|
||||||
|
addr.sin_len = sizeof (struct sockaddr_in);
|
||||||
|
#endif /* HAVE_SINLEN */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* sending port must always be the RIP port */
|
||||||
|
addr.sin_port = htons (RIP_PORT_DEFAULT);
|
||||||
|
|
||||||
/* Make datagram socket. */
|
/* Make datagram socket. */
|
||||||
sock = socket (AF_INET, SOCK_DGRAM, 0);
|
sock = socket (AF_INET, SOCK_DGRAM, 0);
|
||||||
if (sock < 0)
|
if (sock < 0)
|
||||||
|
@ -1360,8 +1365,12 @@ rip_create_socket (struct sockaddr_in *to)
|
||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
if (ripd_privs.change (ZPRIVS_LOWER))
|
if (ripd_privs.change (ZPRIVS_LOWER))
|
||||||
zlog_err ("rip_create_socket: could not lower privs");
|
zlog_err ("rip_create_socket: could not lower privs");
|
||||||
zlog_err("cannot bind to port %d: %s",
|
|
||||||
(int)ntohs(addr.sin_port), safe_strerror(save_errno));
|
zlog_err("%s: Can't bind socket %d to %s port %d: %s", __func__,
|
||||||
|
sock, inet_ntoa(addr.sin_addr),
|
||||||
|
(int) ntohs(addr.sin_port),
|
||||||
|
safe_strerror(save_errno));
|
||||||
|
|
||||||
close (sock);
|
close (sock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1440,16 +1449,25 @@ rip_send_packet (u_char * buf, int size, struct sockaddr_in *to,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
struct sockaddr_in from;
|
||||||
|
|
||||||
sin.sin_port = htons (RIP_PORT_DEFAULT);
|
sin.sin_port = htons (RIP_PORT_DEFAULT);
|
||||||
sin.sin_addr.s_addr = htonl (INADDR_RIP_GROUP);
|
sin.sin_addr.s_addr = htonl (INADDR_RIP_GROUP);
|
||||||
|
|
||||||
|
/* multicast send should bind to local interface address */
|
||||||
|
from.sin_family = AF_INET;
|
||||||
|
from.sin_port = htons (RIP_PORT_DEFAULT);
|
||||||
|
from.sin_addr = ifc->address->u.prefix4;
|
||||||
|
#ifdef HAVE_SIN_LEN
|
||||||
|
from.sin_len = sizeof (struct sockaddr_in);
|
||||||
|
#endif /* HAVE_SIN_LEN */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* we have to open a new socket for each packet because this
|
* we have to open a new socket for each packet because this
|
||||||
* is the most portable way to bind to a different source
|
* is the most portable way to bind to a different source
|
||||||
* ipv4 address for each packet.
|
* ipv4 address for each packet.
|
||||||
*/
|
*/
|
||||||
if ( (send_sock = rip_create_socket (&sin)) < 0)
|
if ( (send_sock = rip_create_socket (&from)) < 0)
|
||||||
{
|
{
|
||||||
zlog_warn("rip_send_packet could not create socket.");
|
zlog_warn("rip_send_packet could not create socket.");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -2105,7 +2123,7 @@ rip_output_process (struct connected *ifc, struct sockaddr_in *to,
|
||||||
with larger key string sizes */
|
with larger key string sizes */
|
||||||
char auth_str[RIP_AUTH_SIMPLE_SIZE];
|
char auth_str[RIP_AUTH_SIMPLE_SIZE];
|
||||||
size_t doff; /* offset of digest offset field */
|
size_t doff; /* offset of digest offset field */
|
||||||
int num;
|
int num = 0;
|
||||||
int rtemax;
|
int rtemax;
|
||||||
int subnetted = 0;
|
int subnetted = 0;
|
||||||
|
|
||||||
|
@ -2124,7 +2142,6 @@ rip_output_process (struct connected *ifc, struct sockaddr_in *to,
|
||||||
|
|
||||||
/* Reset stream and RTE counter. */
|
/* Reset stream and RTE counter. */
|
||||||
stream_reset (s);
|
stream_reset (s);
|
||||||
num = 0;
|
|
||||||
rtemax = (RIP_PACKET_MAXSIZ - 4) / 20;
|
rtemax = (RIP_PACKET_MAXSIZ - 4) / 20;
|
||||||
|
|
||||||
/* Get RIP interface. */
|
/* Get RIP interface. */
|
||||||
|
|
Loading…
Reference in a new issue