tcpmss.c (d5939061993c5251fbdb41f9efed60598a261f41) tcpmss.c (057f1760a8171825b260dad27502f74ed5f69faf)
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

--- 82 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
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

--- 82 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 };