Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet implement IP_PKTINFO and IP_RECVPKTINFO.



details:   https://anonhg.NetBSD.org/src/rev/3849cdd26318
branches:  trunk
changeset: 787651:3849cdd26318
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jun 27 19:38:16 2013 +0000

description:
implement IP_PKTINFO and IP_RECVPKTINFO.

diffstat:

 sys/netinet/in.h        |  13 ++++++++++++-
 sys/netinet/in_pcb.h    |  31 +++++++++++++++++--------------
 sys/netinet/ip_input.c  |  22 ++++++++++++++++++++--
 sys/netinet/ip_output.c |  24 ++++++++++++++++++++++--
 4 files changed, 71 insertions(+), 19 deletions(-)

diffs (209 lines):

diff -r c1955878ffd5 -r 3849cdd26318 sys/netinet/in.h
--- a/sys/netinet/in.h  Thu Jun 27 18:54:31 2013 +0000
+++ b/sys/netinet/in.h  Thu Jun 27 19:38:16 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in.h,v 1.88 2013/04/27 21:35:24 joerg Exp $    */
+/*     $NetBSD: in.h,v 1.89 2013/06/27 19:38:16 christos Exp $ */
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -287,6 +287,17 @@
 #endif
 #define        IP_RECVTTL              23   /* bool; receive IP TTL w/dgram */
 #define        IP_MINTTL               24   /* minimum TTL for packet or drop */
+#define        IP_PKTINFO              25   /* int; send interface and src addr */
+#define        IP_RECVPKTINFO          26   /* int; send interface and dst addr */
+
+/*
+ * Information sent in the control message of a datagram socket for
+ * IP_PKTINFO and IP_RECVPKTINFO.
+ */
+struct in_pktinfo {
+       struct in_addr  ipi_addr;       /* src/dst address */
+       unsigned int ipi_ifindex;       /* interface index */
+};
 
 /*
  * Defaults and limits for options
diff -r c1955878ffd5 -r 3849cdd26318 sys/netinet/in_pcb.h
--- a/sys/netinet/in_pcb.h      Thu Jun 27 18:54:31 2013 +0000
+++ b/sys/netinet/in_pcb.h      Thu Jun 27 19:38:16 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_pcb.h,v 1.50 2012/06/25 15:28:39 christos Exp $     */
+/*     $NetBSD: in_pcb.h,v 1.51 2013/06/27 19:38:16 christos Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -100,28 +100,31 @@
 #define        inp_laddr       inp_ip.ip_src
 
 /* flags in inp_flags: */
-#define        INP_RECVOPTS            0x01    /* receive incoming IP options */
-#define        INP_RECVRETOPTS         0x02    /* receive IP options for reply */
-#define        INP_RECVDSTADDR         0x04    /* receive IP dst address */
-#define        INP_HDRINCL             0x08    /* user supplies entire IP header */
-#define        INP_HIGHPORT            0x10    /* (unused; FreeBSD compat) */
-#define        INP_LOWPORT             0x20    /* user wants "low" port binding */
-#define        INP_ANONPORT            0x40    /* port chosen for user */
-#define        INP_RECVIF              0x80    /* receive incoming interface */
+#define        INP_RECVOPTS            0x0001  /* receive incoming IP options */
+#define        INP_RECVRETOPTS         0x0002  /* receive IP options for reply */
+#define        INP_RECVDSTADDR         0x0004  /* receive IP dst address */
+#define        INP_HDRINCL             0x0008  /* user supplies entire IP header */
+#define        INP_HIGHPORT            0x0010  /* (unused; FreeBSD compat) */
+#define        INP_LOWPORT             0x0020  /* user wants "low" port binding */
+#define        INP_ANONPORT            0x0040  /* port chosen for user */
+#define        INP_RECVIF              0x0080  /* receive incoming interface */
 /* XXX should move to an UDP control block */
-#define INP_ESPINUDP           0x100   /* ESP over UDP for NAT-T */
-#define INP_ESPINUDP_NON_IKE   0x200   /* ESP over UDP for NAT-T */
+#define INP_ESPINUDP           0x0100  /* ESP over UDP for NAT-T */
+#define INP_ESPINUDP_NON_IKE   0x0200  /* ESP over UDP for NAT-T */
 #define INP_ESPINUDP_ALL       (INP_ESPINUDP|INP_ESPINUDP_NON_IKE)
-#define INP_NOHEADER           0x400   /* Kernel removes IP header
+#define INP_NOHEADER           0x0400  /* Kernel removes IP header
                                         * before feeding a packet
                                         * to the raw socket user.
                                         * The socket user will
                                         * not supply an IP header.
                                         * Cancels INP_HDRINCL.
                                         */
-#define        INP_RECVTTL             0x800   /* receive incoming IP TTL */
+#define        INP_RECVTTL             0x0800  /* receive incoming IP TTL */
+#define        INP_PKTINFO             0x1000  /* receive dst packet info */
+#define        INP_RECVPKTINFO         0x2000  /* receive dst packet info */
 #define        INP_CONTROLOPTS         (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
-                               INP_RECVIF|INP_RECVTTL)
+                               INP_RECVIF|INP_RECVTTL|INP_RECVPKTINFO|\
+                               INP_PKTINFO)
 
 #define        sotoinpcb(so)           ((struct inpcb *)(so)->so_pcb)
 
diff -r c1955878ffd5 -r 3849cdd26318 sys/netinet/ip_input.c
--- a/sys/netinet/ip_input.c    Thu Jun 27 18:54:31 2013 +0000
+++ b/sys/netinet/ip_input.c    Thu Jun 27 19:38:16 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_input.c,v 1.305 2013/06/08 13:50:22 rmind Exp $     */
+/*     $NetBSD: ip_input.c,v 1.306 2013/06/27 19:38:16 christos Exp $  */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.305 2013/06/08 13:50:22 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.306 2013/06/27 19:38:16 christos Exp $");
 
 #include "opt_inet.h"
 #include "opt_compat_netbsd.h"
@@ -1405,6 +1405,24 @@
                if (*mp)
                        mp = &(*mp)->m_next;
        }
+       if (inp->inp_flags & INP_RECVPKTINFO) {
+               struct in_pktinfo ipi;
+               ipi.ipi_addr = ip->ip_dst;
+               ipi.ipi_ifindex = m->m_pkthdr.rcvif->if_index;
+               *mp = sbcreatecontrol((void *) &ipi,
+                   sizeof(ipi), IP_RECVPKTINFO, IPPROTO_IP);
+               if (*mp)
+                       mp = &(*mp)->m_next;
+       }
+       if (inp->inp_flags & INP_PKTINFO) {
+               struct in_pktinfo ipi;
+               ipi.ipi_addr = ip->ip_src;
+               ipi.ipi_ifindex = m->m_pkthdr.rcvif->if_index;
+               *mp = sbcreatecontrol((void *) &ipi,
+                   sizeof(ipi), IP_PKTINFO, IPPROTO_IP);
+               if (*mp)
+                       mp = &(*mp)->m_next;
+       }
 #ifdef notyet
        /*
         * XXX
diff -r c1955878ffd5 -r 3849cdd26318 sys/netinet/ip_output.c
--- a/sys/netinet/ip_output.c   Thu Jun 27 18:54:31 2013 +0000
+++ b/sys/netinet/ip_output.c   Thu Jun 27 19:38:16 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_output.c,v 1.222 2013/06/08 13:50:22 rmind Exp $    */
+/*     $NetBSD: ip_output.c,v 1.223 2013/06/27 19:38:16 christos Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.222 2013/06/08 13:50:22 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.223 2013/06/27 19:38:16 christos Exp $");
 
 #include "opt_pfil_hooks.h"
 #include "opt_inet.h"
@@ -949,10 +949,12 @@
                case IP_TOS:
                case IP_TTL:
                case IP_MINTTL:
+               case IP_PKTINFO:
                case IP_RECVOPTS:
                case IP_RECVRETOPTS:
                case IP_RECVDSTADDR:
                case IP_RECVIF:
+               case IP_RECVPKTINFO:
                case IP_RECVTTL:
                        error = sockopt_getint(sopt, &optval);
                        if (error)
@@ -979,10 +981,18 @@
        else \
                inp->inp_flags &= ~bit;
 
+                       case IP_PKTINFO:
+                               OPTSET(INP_PKTINFO);
+                               break;
+
                        case IP_RECVOPTS:
                                OPTSET(INP_RECVOPTS);
                                break;
 
+                       case IP_RECVPKTINFO:
+                               OPTSET(INP_RECVPKTINFO);
+                               break;
+
                        case IP_RECVRETOPTS:
                                OPTSET(INP_RECVRETOPTS);
                                break;
@@ -1073,6 +1083,7 @@
                        }
                        break;
 
+               case IP_PKTINFO:
                case IP_TOS:
                case IP_TTL:
                case IP_MINTTL:
@@ -1080,6 +1091,7 @@
                case IP_RECVRETOPTS:
                case IP_RECVDSTADDR:
                case IP_RECVIF:
+               case IP_RECVPKTINFO:
                case IP_RECVTTL:
                case IP_ERRORMTU:
                        switch (sopt->sopt_name) {
@@ -1101,10 +1113,18 @@
 
 #define        OPTBIT(bit)     (inp->inp_flags & bit ? 1 : 0)
 
+                       case IP_PKTINFO:
+                               optval = OPTBIT(INP_PKTINFO);
+                               break;
+
                        case IP_RECVOPTS:
                                optval = OPTBIT(INP_RECVOPTS);
                                break;
 
+                       case IP_RECVPKTINFO:
+                               optval = OPTBIT(INP_RECVPKTINFO);
+                               break;
+
                        case IP_RECVRETOPTS:
                                optval = OPTBIT(INP_RECVRETOPTS);
                                break;



Home | Main Index | Thread Index | Old Index