52#include <sys/endian.h>
54#include <sys/kernel.h>
55#include <sys/malloc.h>
58#include <netinet/in.h>
59#include <netinet/in_systm.h>
60#include <netinet/ip.h>
61#include <netinet/tcp.h>
81static int correct_mss(
struct tcphdr *,
int, uint16_t,
int);
145#define ERROUT(x) { error = (x); goto done; }
164 priv = malloc(
sizeof(*
priv), M_NETGRAPH, M_NOWAIT | M_ZERO);
180 struct ng_mesg *msg, *resp = NULL;
235 if (in == NULL || out == NULL)
270 struct mbuf *m = NULL;
273 int iphlen, tcphlen, pktlen;
278 if (
priv->outHook == NULL)
284 pktlen = m->m_pkthdr.len;
292#define M_CHECK(length) do { \
293 pullup_len += length; \
294 if ((m)->m_pkthdr.len < pullup_len) \
296 if ((m)->m_len < pullup_len && \
297 (((m) = m_pullup((m), pullup_len)) == NULL)) \
303 ip = mtod(m,
struct ip *);
306 if (ip->ip_v != IPVERSION)
310 iphlen = ip->ip_hl << 2;
311 if (iphlen <
sizeof(
struct ip) || iphlen > pktlen )
315 if (!(ip->ip_p == IPPROTO_TCP))
319 M_CHECK(iphlen -
sizeof(
struct ip) +
sizeof(
struct tcphdr));
320 ip = mtod(m,
struct ip *);
321 tcp = (
struct tcphdr *)((caddr_t )ip + iphlen);
324 tcphlen = tcp->th_off << 2;
325 if (tcphlen <
sizeof(
struct tcphdr) || tcphlen > pktlen - iphlen)
329 if (!(tcp->th_flags & TH_SYN) || tcphlen ==
sizeof(
struct tcphdr))
335 M_CHECK(tcphlen -
sizeof(
struct tcphdr));
336 ip = mtod(m,
struct ip *);
337 tcp = (
struct tcphdr *)((caddr_t )ip + iphlen);
343 m->m_pkthdr.csum_flags))
369 LIST_FOREACH(hook2, &node->nd_hooks, hk_hooks) {
372 if (
priv->outHook == hook)
373 priv->outHook = NULL;
396#define TCPMSS_ADJUST_CHECKSUM(acc, cksum) do { \
400 acc = (acc >> 16) + (acc & 0xffff); \
402 cksum = (u_short) ~acc; \
404 acc = (acc >> 16) + (acc & 0xffff); \
406 cksum = (u_short) acc; \
419 for (olen = hlen -
sizeof(
struct tcphdr), opt = (u_char *)(tc + 1);
420 olen > 0; olen -= optlen, opt += optlen) {
421 if (*opt == TCPOPT_EOL)
423 else if (*opt == TCPOPT_NOP)
427 if (optlen <= 0 || optlen > olen)
429 if (*opt == TCPOPT_MAXSEG) {
430 if (optlen != TCPOLEN_MAXSEG)
432 accumulate = be16dec(opt + 2);
433 if (accumulate > maxmss) {
434 if ((
flags & CSUM_TCP) == 0) {
435 accumulate -= maxmss;
436 sum = be16dec(&tc->th_sum);
438 be16enc(&tc->th_sum, sum);
440 be16enc(opt + 2, maxmss);
#define NG_HOOK_NODE(hook)
int ng_rcvmsg_t(node_p node, item_p item, hook_p lasthook)
int ng_disconnect_t(hook_p hook)
#define NG_RESPOND_MSG(error, here, item, resp)
#define NG_HOOK_SET_PRIVATE(hook, val)
int ng_rmnode_self(node_p here)
#define NG_FWD_NEW_DATA(error, item, hook, m)
int ng_rcvdata_t(hook_p hook, item_p item)
#define NG_FREE_ITEM(item)
int ng_constructor_t(node_p node)
#define NG_NODE_NUMHOOKS(node)
#define NGI_GET_MSG(i, m)
int ng_newhook_t(node_p node, hook_p hook, const char *name)
hook_p ng_findhook(node_p node, const char *name)
#define NG_HOOK_PRIVATE(hook)
struct ng_ipfw_hook_priv * hpriv_p
#define NG_MKRESPONSE(rsp, msg, len, how)
const struct ng_parse_type ng_parse_struct_type
const struct ng_parse_type ng_parse_hookbuf_type
static ng_newhook_t ng_tcpmss_newhook
static const struct ng_parse_struct_field ng_tcpmss_hookstat_type_fields[]
static struct ng_type ng_tcpmss_typestruct
static ng_constructor_t ng_tcpmss_constructor
static const struct ng_parse_type ng_tcpmss_hookstat_type
static ng_rcvmsg_t ng_tcpmss_rcvmsg
static ng_disconnect_t ng_tcpmss_disconnect
static int correct_mss(struct tcphdr *, int, uint16_t, int)
static const struct ng_parse_struct_field ng_tcpmss_config_type_fields[]
static ng_rcvdata_t ng_tcpmss_rcvdata
#define TCPMSS_ADJUST_CHECKSUM(acc, cksum)
static const struct ng_cmdlist ng_tcpmss_cmds[]
static const struct ng_parse_type ng_tcpmss_config_type
NETGRAPH_INIT(tcpmss, &ng_tcpmss_typestruct)
#define NG_TCPMSS_CONFIG_INFO
#define NGM_TCPMSS_COOKIE
@ NGM_TCPMSS_GETCLR_STATS
#define NG_TCPMSS_HOOKSTAT_INFO
#define NG_TCPMSS_NODE_TYPE
struct ng_mesg::ng_msghdr header