Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet Allow the multicast_ttl and the multicast_loop o...



details:   https://anonhg.NetBSD.org/src/rev/0fd262218599
branches:  trunk
changeset: 584225:0fd262218599
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Sep 11 21:57:24 2005 +0000

description:
Allow the multicast_ttl and the multicast_loop options to be set with both
u_char and u_int option variables. Original patch from seb.

diffstat:

 sys/netinet/ip_output.c |  45 +++++++++++++++++++++++++++++++--------------
 1 files changed, 31 insertions(+), 14 deletions(-)

diffs (94 lines):

diff -r ba1caa0c66b7 -r 0fd262218599 sys/netinet/ip_output.c
--- a/sys/netinet/ip_output.c   Sun Sep 11 20:38:26 2005 +0000
+++ b/sys/netinet/ip_output.c   Sun Sep 11 21:57:24 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_output.c,v 1.155 2005/08/18 00:30:59 yamt Exp $     */
+/*     $NetBSD: ip_output.c,v 1.156 2005/09/11 21:57:24 christos Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -98,7 +98,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.155 2005/08/18 00:30:59 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.156 2005/09/11 21:57:24 christos Exp $");
 
 #include "opt_pfil_hooks.h"
 #include "opt_inet.h"
@@ -154,6 +154,7 @@
 static struct mbuf *ip_insertoptions(struct mbuf *, struct mbuf *, int *);
 static struct ifnet *ip_multicast_if(struct in_addr *, int *);
 static void ip_mloopback(struct ifnet *, struct mbuf *, struct sockaddr_in *);
+static int ip_getoptval(struct mbuf *, u_int8_t *, u_int);
 
 #ifdef PFIL_HOOKS
 extern struct pfil_head inet_pfil_hook;                        /* XXX */
@@ -1626,6 +1627,32 @@
        return ifp;
 }
 
+static int
+ip_getoptval(struct mbuf *m, u_int8_t *val, u_int maxval)
+{
+       u_int tval;
+
+       if (m == NULL)
+               return EINVAL;
+
+       switch (m->m_len) {
+       case sizeof(u_char):
+               tval = *(mtod(m, u_char *));
+               break;
+       case sizeof(u_int):
+               tval = *(mtod(m, u_int *));
+               break;
+       default:
+               return EINVAL;
+       }
+
+       if (tval > maxval)
+               return EINVAL;
+
+       *val = tval;
+       return 0;
+}
+
 /*
  * Set the IP multicast options in response to user setsockopt().
  */
@@ -1633,7 +1660,6 @@
 ip_setmoptions(int optname, struct ip_moptions **imop, struct mbuf *m)
 {
        int error = 0;
-       u_char loop;
        int i;
        struct in_addr addr;
        struct ip_mreq *mreq;
@@ -1702,11 +1728,7 @@
                /*
                 * Set the IP time-to-live for outgoing multicast packets.
                 */
-               if (m == NULL || m->m_len != 1) {
-                       error = EINVAL;
-                       break;
-               }
-               imo->imo_multicast_ttl = *(mtod(m, u_char *));
+               error = ip_getoptval(m, &imo->imo_multicast_ttl, 255);
                break;
 
        case IP_MULTICAST_LOOP:
@@ -1714,12 +1736,7 @@
                 * Set the loopback flag for outgoing multicast packets.
                 * Must be zero or one.
                 */
-               if (m == NULL || m->m_len != 1 ||
-                  (loop = *(mtod(m, u_char *))) > 1) {
-                       error = EINVAL;
-                       break;
-               }
-               imo->imo_multicast_loop = loop;
+               error = ip_getoptval(m, &imo->imo_multicast_loop, 1);
                break;
 
        case IP_ADD_MEMBERSHIP:



Home | Main Index | Thread Index | Old Index