summaryrefslogtreecommitdiff
path: root/usr.sbin/npppd
diff options
context:
space:
mode:
authorYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2015-12-05 16:10:32 +0000
committerYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2015-12-05 16:10:32 +0000
commit08c6d2cdad85f42f4601f6197e3b8b794f8e81bf (patch)
tree7607997a7352a69c2924fb20a454409a0ea18986 /usr.sbin/npppd
parent56182f399f9a43361b1273373d81fa00c6bcb7d7 (diff)
Pass the pppx_hdr when sending packets through the pppx device and use the
ppp_id in the pppx_hdr to find the associated ppp when receiving the packets from the device.
Diffstat (limited to 'usr.sbin/npppd')
-rw-r--r--usr.sbin/npppd/l2tp/l2tp.h8
-rw-r--r--usr.sbin/npppd/l2tp/l2tp_call.c5
-rw-r--r--usr.sbin/npppd/npppd/npppd.c6
-rw-r--r--usr.sbin/npppd/npppd/npppd.h7
-rw-r--r--usr.sbin/npppd/npppd/npppd_iface.c87
-rw-r--r--usr.sbin/npppd/npppd/npppd_iface.h4
-rw-r--r--usr.sbin/npppd/npppd/ppp.h3
-rw-r--r--usr.sbin/npppd/pppoe/pppoe.h4
-rw-r--r--usr.sbin/npppd/pppoe/pppoe_session.c5
-rw-r--r--usr.sbin/npppd/pptp/pptp_call.c5
10 files changed, 87 insertions, 47 deletions
diff --git a/usr.sbin/npppd/l2tp/l2tp.h b/usr.sbin/npppd/l2tp/l2tp.h
index c7ecc9409cf..cc8a4f283e7 100644
--- a/usr.sbin/npppd/l2tp/l2tp.h
+++ b/usr.sbin/npppd/l2tp/l2tp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: l2tp.h,v 1.11 2015/06/24 05:20:16 yasuoka Exp $ */
+/* $OpenBSD: l2tp.h,v 1.12 2015/12/05 16:10:31 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -30,7 +30,7 @@
/*@file
* header file for the L2TP module
*/
-/* $Id: l2tp.h,v 1.11 2015/06/24 05:20:16 yasuoka Exp $ */
+/* $Id: l2tp.h,v 1.12 2015/12/05 16:10:31 yasuoka Exp $ */
/************************************************************************
* Protocol Constants
@@ -420,9 +420,9 @@ typedef struct _l2tp_call {
/** bound {@link ::_npppd_ppp ppp} */
void *ppp;
/** session ID */
- int session_id;
+ uint16_t session_id;
/** peer's session ID */
- int peer_session_id;
+ uint16_t peer_session_id;
/** next sequence number */
uint16_t snd_nxt;
/** receiving sequence number */
diff --git a/usr.sbin/npppd/l2tp/l2tp_call.c b/usr.sbin/npppd/l2tp/l2tp_call.c
index 843d7182d55..e5df265e39b 100644
--- a/usr.sbin/npppd/l2tp/l2tp_call.c
+++ b/usr.sbin/npppd/l2tp/l2tp_call.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: l2tp_call.c,v 1.18 2015/07/20 19:03:54 yasuoka Exp $ */
+/* $OpenBSD: l2tp_call.c,v 1.19 2015/12/05 16:10:31 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-/* $Id: l2tp_call.c,v 1.18 2015/07/20 19:03:54 yasuoka Exp $ */
+/* $Id: l2tp_call.c,v 1.19 2015/12/05 16:10:31 yasuoka Exp $ */
/**@file L2TP LNS call */
#include <sys/types.h>
#include <sys/socket.h>
@@ -1008,6 +1008,7 @@ l2tp_call_bind_ppp(l2tp_call *_this, dialin_proxy_info *dpi)
_this->ppp = ppp;
ppp->tunnel_type = NPPPD_TUNNEL_L2TP;
+ ppp->tunnel_session_id = _this->session_id;
ppp->phy_context = _this;
ppp->send_packet = l2tp_call_ppp_output;
ppp->phy_close = l2tp_call_closed_by_ppp;
diff --git a/usr.sbin/npppd/npppd/npppd.c b/usr.sbin/npppd/npppd/npppd.c
index ac5ce30a387..2e4e7d3a7b5 100644
--- a/usr.sbin/npppd/npppd/npppd.c
+++ b/usr.sbin/npppd/npppd/npppd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: npppd.c,v 1.42 2015/11/09 01:14:22 yasuoka Exp $ */
+/* $OpenBSD: npppd.c,v 1.43 2015/12/05 16:10:31 yasuoka Exp $ */
/*-
* Copyright (c) 2005-2008,2009 Internet Initiative Japan Inc.
@@ -29,7 +29,7 @@
* Next pppd(nppd). This file provides a npppd daemon process and operations
* for npppd instance.
* @author Yasuoka Masahiko
- * $Id: npppd.c,v 1.42 2015/11/09 01:14:22 yasuoka Exp $
+ * $Id: npppd.c,v 1.43 2015/12/05 16:10:31 yasuoka Exp $
*/
#include "version.h"
#include <sys/param.h> /* ALIGNED_POINTER */
@@ -874,7 +874,7 @@ npppd_network_output(npppd *_this, npppd_ppp *ppp, int proto, u_char *pktp,
}
}
#endif
- npppd_iface_write(ppp_iface(ppp), proto, pktp, lpktp);
+ npppd_iface_write(ppp_iface(ppp), ppp, proto, pktp, lpktp);
}
#ifdef USE_NPPPD_PIPEX
diff --git a/usr.sbin/npppd/npppd/npppd.h b/usr.sbin/npppd/npppd/npppd.h
index 2806d5c3c7a..9f583fbea6e 100644
--- a/usr.sbin/npppd/npppd/npppd.h
+++ b/usr.sbin/npppd/npppd/npppd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: npppd.h,v 1.16 2015/01/19 01:48:59 deraadt Exp $ */
+/* $OpenBSD: npppd.h,v 1.17 2015/12/05 16:10:31 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -57,6 +57,11 @@
#define NPPPD_TUNNEL_PPPOE 3 /** PPPoE Tunnel Type */
#define NPPPD_TUNNEL_SSTP 4 /** SSTP Tunnel Type */
+#define npppd_pipex_proto(_tunnel) \
+ (((_tunnel) == NPPPD_TUNNEL_L2TP)? PIPEX_PROTO_L2TP : \
+ ((_tunnel) == NPPPD_TUNNEL_PPTP)? PIPEX_PROTO_PPTP : \
+ ((_tunnel) == NPPPD_TUNNEL_PPPOE)? PIPEX_PROTO_PPPOE : -1)
+
#define NPPPD_AUTH_METHODS_PAP 0x0001
#define NPPPD_AUTH_METHODS_CHAP 0x0002
#define NPPPD_AUTH_METHODS_MSCHAPV2 0x0004
diff --git a/usr.sbin/npppd/npppd/npppd_iface.c b/usr.sbin/npppd/npppd/npppd_iface.c
index 4a746ea55d7..1f95dbd0ee2 100644
--- a/usr.sbin/npppd/npppd/npppd_iface.c
+++ b/usr.sbin/npppd/npppd/npppd_iface.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: npppd_iface.c,v 1.12 2015/10/11 07:32:06 guenther Exp $ */
+/* $OpenBSD: npppd_iface.c,v 1.13 2015/12/05 16:10:31 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-/* $Id: npppd_iface.c,v 1.12 2015/10/11 07:32:06 guenther Exp $ */
+/* $Id: npppd_iface.c,v 1.13 2015/12/05 16:10:31 yasuoka Exp $ */
/**@file
* The interface of npppd and kernel.
* This is an implementation to use tun(4) or pppx(4).
@@ -41,6 +41,8 @@
#include <net/if_dl.h>
#include <net/if_tun.h>
#include <net/if_types.h>
+#include <net/if.h>
+#include <net/pipex.h>
#include <fcntl.h>
@@ -86,11 +88,13 @@
#define NPPPD_IFACE_DBG(x)
#endif
+static void npppd_iface_network_input_ipv4(npppd_iface *, struct pppx_hdr *,
+ u_char *, int);
static void npppd_iface_network_input(npppd_iface *, u_char *, int);
static int npppd_iface_setup_ip(npppd_iface *);
static void npppd_iface_io_event_handler (int, short, void *);
static int npppd_iface_log (npppd_iface *, int, const char *, ...)
- __printflike(3,4);
+ __printflike(3,4);
#ifdef USE_NPPPD_PIPEX
static int npppd_iface_pipex_enable(npppd_iface *_this);
@@ -481,7 +485,8 @@ npppd_iface_network_input_delegate(struct radish *radish, void *args0)
}
static void
-npppd_iface_network_input_ipv4(npppd_iface *_this, u_char *pktp, int lpktp)
+npppd_iface_network_input_ipv4(npppd_iface *_this, struct pppx_hdr *pppx,
+ u_char *pktp, int lpktp)
{
struct ip *iphdr;
npppd *_npppd;
@@ -498,17 +503,23 @@ npppd_iface_network_input_ipv4(npppd_iface *_this, u_char *pktp, int lpktp)
npppd_iface_log(_this, LOG_ERR, "Received short packet.");
return;
}
- if (IN_MULTICAST(ntohl(iphdr->ip_dst.s_addr))) {
- NPPPD_IFACE_ASSERT(((npppd *)(_this->npppd))->rd != NULL);
- input_arg._this = _this;
- input_arg.pktp = pktp;
- input_arg.lpktp = lpktp;
- /* delegate */
- rd_walktree(((npppd *)(_this->npppd))->rd,
- npppd_iface_network_input_delegate, &input_arg);
- return;
+ if (_this->using_pppx)
+ ppp = npppd_get_ppp_by_id(_npppd, pppx->pppx_id);
+ else {
+ if (IN_MULTICAST(ntohl(iphdr->ip_dst.s_addr))) {
+ NPPPD_IFACE_ASSERT(
+ ((npppd *)(_this->npppd))->rd != NULL);
+ input_arg._this = _this;
+ input_arg.pktp = pktp;
+ input_arg.lpktp = lpktp;
+ /* delegate */
+ rd_walktree(((npppd *)(_this->npppd))->rd,
+ npppd_iface_network_input_delegate, &input_arg);
+ return;
+ }
+ ppp = npppd_get_ppp_by_ip(_npppd, iphdr->ip_dst);
}
- ppp = npppd_get_ppp_by_ip(_npppd, iphdr->ip_dst);
+
if (ppp == NULL) {
#ifdef NPPPD_DEBUG
log_printf(LOG_INFO, "%s received a packet to unknown "
@@ -547,6 +558,18 @@ static void
npppd_iface_network_input(npppd_iface *_this, u_char *pktp, int lpktp)
{
uint32_t af;
+ struct pppx_hdr *pppx = NULL;
+
+ if (_this->using_pppx) {
+ if (lpktp < sizeof(struct pppx_hdr)) {
+ npppd_iface_log(_this, LOG_ERR,
+ "Received short packet.");
+ return;
+ }
+ pppx = (struct pppx_hdr *)pktp;
+ pktp += sizeof(struct pppx_hdr);
+ lpktp -= sizeof(struct pppx_hdr);
+ }
if (lpktp < sizeof(uint32_t)) {
npppd_iface_log(_this, LOG_ERR, "Received short packet.");
@@ -557,7 +580,7 @@ npppd_iface_network_input(npppd_iface *_this, u_char *pktp, int lpktp)
switch (af) {
case AF_INET:
- npppd_iface_network_input_ipv4(_this, pktp, lpktp);
+ npppd_iface_network_input_ipv4(_this, pppx, pktp, lpktp);
break;
default:
@@ -569,25 +592,33 @@ npppd_iface_network_input(npppd_iface *_this, u_char *pktp, int lpktp)
/** write to tunnel device */
void
-npppd_iface_write(npppd_iface *_this, int proto, u_char *pktp, int lpktp)
+npppd_iface_write(npppd_iface *_this, npppd_ppp *ppp, int proto, u_char *pktp,
+ int lpktp)
{
- int err;
+ int niov = 0, tlen;
uint32_t th;
- struct iovec iov[2];
-
+ struct iovec iov[3];
+ struct pppx_hdr pppx;
NPPPD_IFACE_ASSERT(_this != NULL);
NPPPD_IFACE_ASSERT(_this->devf >= 0);
+ tlen = 0;
th = htonl(proto);
-
- iov[0].iov_base = &th;
- iov[0].iov_len = sizeof(th);
- iov[1].iov_base = pktp;
- iov[1].iov_len = lpktp;
-
- err = writev(_this->devf, iov, countof(iov));
-
- if (err != lpktp + sizeof(th))
+ if (_this->using_pppx) {
+ pppx.pppx_proto = npppd_pipex_proto(ppp->tunnel_type);
+ pppx.pppx_id = ppp->tunnel_session_id;
+ iov[niov].iov_base = &pppx;
+ iov[niov++].iov_len = sizeof(pppx);
+ tlen += sizeof(pppx);
+ }
+ iov[niov].iov_base = &th;
+ iov[niov++].iov_len = sizeof(th);
+ tlen += sizeof(th);
+ iov[niov].iov_base = pktp;
+ iov[niov++].iov_len = lpktp;
+ tlen += lpktp;
+
+ if (writev(_this->devf, iov, niov) != tlen)
npppd_iface_log(_this, LOG_ERR, "write failed: %m");
}
diff --git a/usr.sbin/npppd/npppd/npppd_iface.h b/usr.sbin/npppd/npppd/npppd_iface.h
index 7a1b76f0496..04f86dd1f62 100644
--- a/usr.sbin/npppd/npppd/npppd_iface.h
+++ b/usr.sbin/npppd/npppd/npppd_iface.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: npppd_iface.h,v 1.6 2012/09/18 13:14:08 yasuoka Exp $ */
+/* $OpenBSD: npppd_iface.h,v 1.7 2015/12/05 16:10:31 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -69,7 +69,7 @@ int npppd_iface_reinit (npppd_iface *, struct iface *);
int npppd_iface_start (npppd_iface *);
void npppd_iface_stop (npppd_iface *);
void npppd_iface_fini (npppd_iface *);
-void npppd_iface_write (npppd_iface *, int proto, u_char *, int);
+void npppd_iface_write (npppd_iface *, npppd_ppp *, int proto, u_char *, int);
#ifdef __cplusplus
}
diff --git a/usr.sbin/npppd/npppd/ppp.h b/usr.sbin/npppd/npppd/ppp.h
index cf5a701b6bb..f2a0fdb5d6e 100644
--- a/usr.sbin/npppd/npppd/ppp.h
+++ b/usr.sbin/npppd/npppd/ppp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ppp.h,v 1.18 2015/07/23 09:04:06 yasuoka Exp $ */
+/* $OpenBSD: ppp.h,v 1.19 2015/12/05 16:10:31 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -454,6 +454,7 @@ struct _npppd_ppp {
/** Physical layer */
int tunnel_type; /** PPP Tunnel Type */
+ uint16_t tunnel_session_id; /** Tunnel Sesion Id */
uint16_t mru; /** MRU */
uint16_t peer_mru; /** Peer's MRU */
void *phy_context; /** Context of physical layer */
diff --git a/usr.sbin/npppd/pppoe/pppoe.h b/usr.sbin/npppd/pppoe/pppoe.h
index da36e480588..12e3209c144 100644
--- a/usr.sbin/npppd/pppoe/pppoe.h
+++ b/usr.sbin/npppd/pppoe/pppoe.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pppoe.h,v 1.6 2014/07/21 01:51:11 guenther Exp $ */
+/* $OpenBSD: pppoe.h,v 1.7 2015/12/05 16:10:31 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -159,7 +159,7 @@ typedef struct _pppoe_session {
/** Pointer to the PPP context */
void *ppp;
/** Session id */
- int session_id;
+ uint16_t session_id;
/** Cookie number */
int acookie;
/** Peer ethernet address */
diff --git a/usr.sbin/npppd/pppoe/pppoe_session.c b/usr.sbin/npppd/pppoe/pppoe_session.c
index 213712b4474..7f163f7f902 100644
--- a/usr.sbin/npppd/pppoe/pppoe_session.c
+++ b/usr.sbin/npppd/pppoe/pppoe_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pppoe_session.c,v 1.10 2015/09/13 08:22:10 mpi Exp $ */
+/* $OpenBSD: pppoe_session.c,v 1.11 2015/12/05 16:10:31 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -28,7 +28,7 @@
/**@file
* Session management of PPPoE protocol
- * $Id: pppoe_session.c,v 1.10 2015/09/13 08:22:10 mpi Exp $
+ * $Id: pppoe_session.c,v 1.11 2015/12/05 16:10:31 yasuoka Exp $
*/
#include <sys/types.h>
@@ -493,6 +493,7 @@ pppoe_session_bind_ppp(pppoe_session *_this)
_this->ppp = ppp;
ppp->tunnel_type = NPPPD_TUNNEL_PPPOE;
+ ppp->tunnel_session_id = _this->session_id;
ppp->phy_context = _this;
ppp->send_packet = pppoe_session_ppp_output;
ppp->phy_close = pppoe_session_close_by_ppp;
diff --git a/usr.sbin/npppd/pptp/pptp_call.c b/usr.sbin/npppd/pptp/pptp_call.c
index cbf04fb0573..4d0c3d0a7c4 100644
--- a/usr.sbin/npppd/pptp/pptp_call.c
+++ b/usr.sbin/npppd/pptp/pptp_call.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pptp_call.c,v 1.8 2015/01/19 01:48:59 deraadt Exp $ */
+/* $OpenBSD: pptp_call.c,v 1.9 2015/12/05 16:10:31 yasuoka Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-/* $Id: pptp_call.c,v 1.8 2015/01/19 01:48:59 deraadt Exp $ */
+/* $Id: pptp_call.c,v 1.9 2015/12/05 16:10:31 yasuoka Exp $ */
/**@file PPTP Call */
/* currently it supports PAC mode only */
#include <sys/types.h>
@@ -744,6 +744,7 @@ pptp_call_bind_ppp(pptp_call *_this)
ppp->phy_context = _this;
ppp->tunnel_type = NPPPD_TUNNEL_PPTP;
+ ppp->tunnel_session_id = _this->id;
ppp->send_packet = pptp_call_ppp_output;
ppp->phy_close = pptp_call_closed_by_ppp;