From owner-freebsd-ipfw@FreeBSD.ORG Thu May 8 16:12:19 2008 Return-Path: Delivered-To: freebsd-ipfw@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 31B77106566B for ; Thu, 8 May 2008 16:12:19 +0000 (UTC) (envelope-from ermal.luci@gmail.com) Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.237]) by mx1.freebsd.org (Postfix) with ESMTP id 081738FC17 for ; Thu, 8 May 2008 16:12:18 +0000 (UTC) (envelope-from ermal.luci@gmail.com) Received: by rv-out-0506.google.com with SMTP id b25so1389267rvf.43 for ; Thu, 08 May 2008 09:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:mime-version:content-type:content-transfer-encoding:content-disposition; bh=8RyzlQs4cc5WdFiv4FdT9s5NP2JzE6GA3Mcdl7pebj8=; b=f1a66W7ZXL9Kg9C/f5v5LRxiUe/ciuO9bIYXMiP+sNWdh58GAcKkrc4s445LNPIQ1YvnQ6DbgbpcNjlE7OGnMO6va5kaMweMrM1YCS2efUI/mXwn7OQYJo5yC4OmCk2r+d2u9HxDWaduNsB2SbSBw5QMt7t94Wz/7PsK/rYKhjY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:mime-version:content-type:content-transfer-encoding:content-disposition; b=Cnmf625WJmuSpx4MbgCC0g3m4K7NMGoCCIMH2Oqoz5Ba6qHb2ltxrK6iJ8m0D2NzC52MfImxmZXpwqdlO8Y1GSJzOQ0DAhdDEwqGOPry1ayOwI8rcdRt9odycuALpTfW6nI9cvwjL8d2pyTTDlO7dL2Gnh2KDRdxFuQkICPgh0U= Received: by 10.140.177.15 with SMTP id z15mr1596138rve.70.1210261499819; Thu, 08 May 2008 08:44:59 -0700 (PDT) Received: by 10.140.135.3 with HTTP; Thu, 8 May 2008 08:44:59 -0700 (PDT) Message-ID: <9a542da30805080844t395c8c81sd313fc2fd1780fcb@mail.gmail.com> Date: Thu, 8 May 2008 17:44:59 +0200 From: "=?ISO-8859-1?Q?Ermal_Lu=E7i?=" To: freebsd-ipfw@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Cc: 482254ac@razorfever.net Subject: Re: Dummynet, gif, and ipsec X-BeenThere: freebsd-ipfw@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: IPFW Technical Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 May 2008 16:12:19 -0000 > Date: Wed, 07 May 2008 21:41:23 -0400 > From: "Derek (freebsd-ipfw)" <482254ac@razorfever.net> > Subject: Dummynet, gif, and ipsec > To: freebsd-ipfw@freebsd.org > Message-ID: <48225A43.3080909@razorfever.net> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Hello, > > I am trying to do some traffic shaping on my router using dummynet. The > router is one endpoint in an ipsec tunnel (configured as the handbook > suggests). > > I'm running voip inside ipsec, so the goal here is to minimize the delay > in transmitting the encapsulated voip packets. I'd like to be able to > classify other traffic inside ipsec as well. > > I currently have my outgoing pipe configured with 5 queues: > > pipe 10 config delay 0 #outgoing pipe send > queue 101 config pipe 10 weight 100 #highest priority > queue 102 config pipe 10 weight 20 > queue 103 config pipe 10 weight 5 > queue 104 config pipe 10 weight 1 #lowest priority > > I have all of my outgoing ipsec queued into queue 101, with most of my > other traffic hitting the other queues. > > I have set up additional queues to run over top of my > gif interfaces: > > pipe 20 config delay 0 #VPN outgoing pipe (gif*) send > queue 201 config pipe 20 weight 100 #highest priority > queue 202 config pipe 20 weight 20 > queue 203 config pipe 20 weight 5 > queue 204 config pipe 20 weight 1 #lowest priority > > As I'm running a tunnel, I have specific subnets that are communicating > over the gif interfaces. > > If I simply allow the traffic, everything works fine: > > add 7200 allow ip from table(1) to table(1) > > If I try to queue traffic going out, packets disappear right after the > queue: > > add 7020 queue 203 ip from table(1) to table(1) out via gif* > add 7025 count ip from table(1) to table(1) out via gif* > add 7200 allow ip from table(1) to table(1) > > I zero my stats, and let the traffic run for a little while. When I > show my stats again, there is a gross discrepancy in the counts at 7020, > and 7025. Packets that normally show up on the other end of the tunnel, > don't. If I remove the count, the packets still don't show up. > > If anyone can recognize why this is happening, or provide suggestions on > how to troubleshoot it, I'd greatly appreciate it. > > If your are doing a similar approach successfully, I'd like to know. > > If you have alternative suggestions on how to shape traffic based on > what is inside an ipsec tunnel, that is also appreciated. > > I tried using IPFW's tag command, and I think that is the best way to do > what I want to do, period. Tag the unencrypted data as it is going out > the gif interface, and queue the IPSEC traffic based on the packet tag, > but the tag disappears after IPSEC processing. > > Also, I'm aware of using the IP TOS flags for this, and I may have to go > that route (based on the research I've done), but I want to know why > what I'm currently is failing the way it is. The TOS flags don't seem > as flexible, as there are only a few classes that I can use, and there > isn't any built-in way to modify these flags. I'd have to use netgraph, > or divert, and I'm not too keen on either of these approaches right now. > Well this is a patch to shape IPSec tunnels with ALTQ and FreeBSD 6.3 as you are running. It is another alternative to dummynet though it have been tested with pf but should work with ipfw too since it knows about ALTQ. Hope it helps! Ermal Index: sys/net/if_enc.c =================================================================== RCS file: /home/eri/FreeBSD/src/sys/net/if_enc.c,v retrieving revision 1.5.2.2.2.1 diff -u -r1.5.2.2.2.1 if_enc.c --- sys/net/if_enc.c 29 Dec 2007 17:29:11 -0000 1.5.2.2.2.1 +++ sys/net/if_enc.c 10 Feb 2008 01:19:41 -0000 @@ -48,6 +48,8 @@ #include #include +#include + #include #include #include @@ -194,10 +196,12 @@ } int -ipsec_filter(struct mbuf **mp, int dir) +ipsec_filter(struct mbuf **mp, struct secasindex *saidx, int dir) { int error, i; struct ip *ip; + struct m_tag *t; + struct altq_tag *atag; KASSERT(encif != NULL, ("%s: encif is null", __func__)); @@ -267,6 +271,11 @@ if (error != 0) goto bad; + if (saidx && (t = m_tag_find(*mp, PACKET_TAG_PF_QID, NULL)) != NULL) { + atag = (struct altq_tag *)(t + 1); + saidx->qid = atag->qid; + } + return (error); bad: Index: sys/netipsec/ipsec.h =================================================================== RCS file: /home/eri/FreeBSD/src/sys/netipsec/ipsec.h,v retrieving revision 1.8.2.2 diff -u -r1.8.2.2 ipsec.h --- sys/netipsec/ipsec.h 24 Jul 2006 23:20:59 -0000 1.8.2.2 +++ sys/netipsec/ipsec.h 8 Feb 2008 17:13:03 -0000 @@ -413,7 +413,7 @@ extern struct mbuf *m_makespace(struct mbuf *m0, int skip, int hlen, int *off); extern caddr_t m_pad(struct mbuf *m, int n); extern int m_striphdr(struct mbuf *m, int skip, int hlen); -extern int ipsec_filter(struct mbuf **, int); +extern int ipsec_filter(struct mbuf **, struct secasindex *, int); extern void ipsec_bpf(struct mbuf *, struct secasvar *, int); #endif /* _KERNEL */ Index: sys/netipsec/ipsec_input.c =================================================================== RCS file: /home/eri/FreeBSD/src/sys/netipsec/ipsec_input.c,v retrieving revision 1.9.2.2 diff -u -r1.9.2.2 ipsec_input.c --- sys/netipsec/ipsec_input.c 24 Jul 2006 23:20:59 -0000 1.9.2.2 +++ sys/netipsec/ipsec_input.c 8 Feb 2008 16:53:05 -0000 @@ -451,7 +451,7 @@ ipsec_bpf(m, sav, AF_INET); if (prot != IPPROTO_IPIP) - if ((error = ipsec_filter(&m, 1)) != 0) + if ((error = ipsec_filter(&m, &sav->sah->saidx, 1)) != 0) return (error); #endif Index: sys/netipsec/ipsec_output.c =================================================================== RCS file: /home/eri/FreeBSD/src/sys/netipsec/ipsec_output.c,v retrieving revision 1.10.8.1 diff -u -r1.10.8.1 ipsec_output.c --- sys/netipsec/ipsec_output.c 24 Jul 2006 23:20:59 -0000 1.10.8.1 +++ sys/netipsec/ipsec_output.c 9 Feb 2008 17:49:47 -0000 @@ -44,6 +44,9 @@ #include #include +#ifdef DEV_ENC +#include +#endif #include #include @@ -160,6 +163,25 @@ } key_sa_recordxfer(sav, m); /* record data transfer */ +#ifdef DEV_ENC + /* + * Restore previous queue selected by the classifier for the + * packet. + */ + if (saidx->qid) { + mtag = m_tag_get(PACKET_TAG_PF_QID, sizeof(struct altq_tag), + M_NOWAIT); + if (mtag != NULL) { /* Safe to ignore */ + struct altq_tag *atag; + atag = (struct altq_tag *)(mtag + 1); + atag->qid = saidx->qid; + /* add hints for ecn */ + atag->af = saidx->dst.sa.sa_family; + atag->hdr = NULL; /* This should be safe! */ + m_tag_prepend(m, mtag); + } + } +#endif /* * We're done with IPsec processing, transmit the packet using the * appropriate network protocol (IP or IPv6). SPD lookup will be @@ -362,7 +384,7 @@ #ifdef DEV_ENC /* pass the mbuf to enc0 for packet filtering */ - if ((error = ipsec_filter(&m, 2)) != 0) + if ((error = ipsec_filter(&m, &sav->sah->saidx, 2)) != 0) goto bad; #endif Index: sys/netipsec/keydb.h =================================================================== RCS file: /home/eri/FreeBSD/src/sys/netipsec/keydb.h,v retrieving revision 1.5 diff -u -r1.5 keydb.h --- sys/netipsec/keydb.h 7 Jan 2005 01:45:46 -0000 1.5 +++ sys/netipsec/keydb.h 8 Feb 2008 17:12:01 -0000 @@ -58,6 +58,9 @@ u_int8_t mode; /* mode of protocol, see ipsec.h */ u_int32_t reqid; /* reqid id who owned this SA */ /* see IPSEC_MANUAL_REQID_MAX. */ + u_int32_t qid; /* used for ALTQ shaping inside */ + /* tunnel */ + }; /* Security Association Data Base */ Index: sys/netipsec/xform_ipip.c =================================================================== RCS file: /home/eri/FreeBSD/src/sys/netipsec/xform_ipip.c,v retrieving revision 1.11.2.2 diff -u -r1.11.2.2 xform_ipip.c --- sys/netipsec/xform_ipip.c 24 Jul 2006 23:20:59 -0000 1.11.2.2 +++ sys/netipsec/xform_ipip.c 8 Feb 2008 16:54:41 -0000 @@ -348,7 +348,7 @@ #ifdef DEV_ENC /* pass the mbuf to enc0 for packet filtering */ - if (ipsec_filter(&m, 1) != 0) + if (ipsec_filter(&m, NULL, 1) != 0) return; #endif > Best regards, and thanks! > -- Derek > > > > More details about the machine: > > Running 6.3-RELEASE > > /etc/sysctl.conf: > net.inet.ip.fw.one_pass=0 > > Kernel: > include SMP > ident GW2 > > options MPTABLE_FORCE_HTT > options NO_F00F_HACK > options DEVICE_POLLING > options AUTO_EOI_1 > > options IPSEC > options IPSEC_ESP > options IPSEC_FILTERGIF > > device carp > device disc > > options IPFIREWALL > options IPFIREWALL_VERBOSE > options IPFIREWALL_FORWARD > options IPDIVERT > options IPSTEALTH > options TCP_DROP_SYNFIN > options DUMMYNET > options ZERO_COPY_SOCKETS > options HZ=1000