Deleted Added
full compact
tcpmss.c (131265) tcpmss.c (134789)
1/*-
2 * Copyright (c) 2000 Ruslan Ermilov and Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2000 Ruslan Ermilov and Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/usr.sbin/ppp/tcpmss.c 131265 2004-06-29 07:40:38Z brian $
26 * $FreeBSD: head/usr.sbin/ppp/tcpmss.c 134789 2004-09-05 01:46:52Z brian $
27 */
28
29#include <sys/param.h>
30
31#include <sys/socket.h>
32#include <net/route.h>
33#include <netinet/in_systm.h>
34#include <netinet/in.h>

--- 56 unchanged lines hidden (view full) ---

91 } else { \
92 acc = (acc >> 16) + (acc & 0xffff); \
93 acc += acc >> 16; \
94 cksum = (u_short) acc; \
95 } \
96}
97
98static void
27 */
28
29#include <sys/param.h>
30
31#include <sys/socket.h>
32#include <net/route.h>
33#include <netinet/in_systm.h>
34#include <netinet/in.h>

--- 56 unchanged lines hidden (view full) ---

91 } else { \
92 acc = (acc >> 16) + (acc & 0xffff); \
93 acc += acc >> 16; \
94 cksum = (u_short) acc; \
95 } \
96}
97
98static void
99MSSFixup(struct tcphdr *tc, ssize_t pktlen, u_int16_t maxmss)
99MSSFixup(struct tcphdr *tc, size_t pktlen, u_int16_t maxmss)
100{
100{
101 int hlen, olen, optlen;
101 size_t hlen, olen, optlen;
102 u_char *opt;
103 u_int16_t *mss;
104 int accumulate;
105
106 hlen = tc->th_off << 2;
107
108 /* Invalid header length or header without options. */
109 if (hlen <= sizeof(struct tcphdr) || hlen > pktlen)

--- 29 unchanged lines hidden (view full) ---

139 }
140 }
141}
142
143static struct mbuf *
144tcpmss_Check(struct bundle *bundle, struct mbuf *bp)
145{
146 struct ip *pip;
102 u_char *opt;
103 u_int16_t *mss;
104 int accumulate;
105
106 hlen = tc->th_off << 2;
107
108 /* Invalid header length or header without options. */
109 if (hlen <= sizeof(struct tcphdr) || hlen > pktlen)

--- 29 unchanged lines hidden (view full) ---

139 }
140 }
141}
142
143static struct mbuf *
144tcpmss_Check(struct bundle *bundle, struct mbuf *bp)
145{
146 struct ip *pip;
147 int hlen, plen;
147 size_t hlen, plen;
148
149 if (!Enabled(bundle, OPT_TCPMSSFIXUP))
150 return bp;
151
152 bp = m_pullup(bp);
153 plen = m_length(bp);
154 pip = (struct ip *)MBUF_CTOP(bp);
155 hlen = pip->ip_hl << 2;
156
157 /*
158 * Check for MSS option only for TCP packets with zero fragment offsets
159 * and correct total and header lengths.
160 */
161 if (pip->ip_p == IPPROTO_TCP && (ntohs(pip->ip_off) & IP_OFFMASK) == 0 &&
162 ntohs(pip->ip_len) == plen && hlen <= plen &&
148
149 if (!Enabled(bundle, OPT_TCPMSSFIXUP))
150 return bp;
151
152 bp = m_pullup(bp);
153 plen = m_length(bp);
154 pip = (struct ip *)MBUF_CTOP(bp);
155 hlen = pip->ip_hl << 2;
156
157 /*
158 * Check for MSS option only for TCP packets with zero fragment offsets
159 * and correct total and header lengths.
160 */
161 if (pip->ip_p == IPPROTO_TCP && (ntohs(pip->ip_off) & IP_OFFMASK) == 0 &&
162 ntohs(pip->ip_len) == plen && hlen <= plen &&
163 plen - hlen >= sizeof(struct tcphdr))
163 plen >= sizeof(struct tcphdr) + hlen)
164 MSSFixup((struct tcphdr *)(MBUF_CTOP(bp) + hlen), plen - hlen,
165 MAXMSS(bundle->iface->mtu));
166
167 return bp;
168}
169
170static struct mbuf *
164 MSSFixup((struct tcphdr *)(MBUF_CTOP(bp) + hlen), plen - hlen,
165 MAXMSS(bundle->iface->mtu));
166
167 return bp;
168}
169
170static struct mbuf *
171tcpmss_LayerPush(struct bundle *bundle, struct link *l, struct mbuf *bp,
172 int pri, u_short *proto)
171tcpmss_LayerPush(struct bundle *bundle, struct link *l __unused,
172 struct mbuf *bp, int pri __unused, u_short *proto __unused)
173{
174 return tcpmss_Check(bundle, bp);
175}
176
177static struct mbuf *
173{
174 return tcpmss_Check(bundle, bp);
175}
176
177static struct mbuf *
178tcpmss_LayerPull(struct bundle *bundle, struct link *l, struct mbuf *bp,
179 u_short *proto)
178tcpmss_LayerPull(struct bundle *bundle, struct link *l __unused,
179 struct mbuf *bp, u_short *proto __unused)
180{
181 return tcpmss_Check(bundle, bp);
182}
183
184struct layer tcpmsslayer =
185 { LAYER_PROTO, "tcpmss", tcpmss_LayerPush, tcpmss_LayerPull };
180{
181 return tcpmss_Check(bundle, bp);
182}
183
184struct layer tcpmsslayer =
185 { LAYER_PROTO, "tcpmss", tcpmss_LayerPush, tcpmss_LayerPull };