ip_divert.h revision 126239
1126239Smlaier/*-
2126239Smlaier * Copyright (c) 2003 Sam Leffler, Errno Consulting
3126239Smlaier * All rights reserved.
4126239Smlaier *
5126239Smlaier * Redistribution and use in source and binary forms, with or without
6126239Smlaier * modification, are permitted provided that the following conditions
7126239Smlaier * are met:
8126239Smlaier * 1. Redistributions of source code must retain the above copyright
9126239Smlaier *    notice, this list of conditions and the following disclaimer,
10126239Smlaier *    without modification.
11126239Smlaier * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12126239Smlaier *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13126239Smlaier *    redistribution must be conditioned upon including a substantially
14126239Smlaier *    similar Disclaimer requirement for further binary redistribution.
15126239Smlaier * 3. Neither the names of the above-listed copyright holders nor the names
16126239Smlaier *    of any contributors may be used to endorse or promote products derived
17126239Smlaier *    from this software without specific prior written permission.
18126239Smlaier *
19126239Smlaier * NO WARRANTY
20126239Smlaier * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21126239Smlaier * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22126239Smlaier * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
23126239Smlaier * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
24126239Smlaier * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
25126239Smlaier * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26126239Smlaier * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27126239Smlaier * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
28126239Smlaier * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29126239Smlaier * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30126239Smlaier * THE POSSIBILITY OF SUCH DAMAGES.
31126239Smlaier *
32126239Smlaier * $FreeBSD: head/sys/netinet/ip_divert.h 126239 2004-02-25 19:55:29Z mlaier $
33126239Smlaier */
34126239Smlaier
35126239Smlaier#ifndef _NETINET_IP_DIVERT_H_
36126239Smlaier#define	_NETINET_IP_DIVERT_H_
37126239Smlaier
38126239Smlaier/*
39126239Smlaier * Divert socket definitions.
40126239Smlaier */
41126239Smlaier
42126239Smlaierstruct divert_tag {
43126239Smlaier	u_int32_t	info;		/* port & flags */
44126239Smlaier	u_int16_t	cookie;		/* ipfw rule number */
45126239Smlaier};
46126239Smlaier
47126239Smlaier/*
48126239Smlaier * Return the divert cookie associated with the mbuf; if any.
49126239Smlaier */
50126239Smlaierstatic __inline u_int16_t
51126239Smlaierdivert_cookie(struct m_tag *mtag)
52126239Smlaier{
53126239Smlaier	return ((struct divert_tag *)(mtag+1))->cookie;
54126239Smlaier}
55126239Smlaierstatic __inline u_int16_t
56126239Smlaierdivert_find_cookie(struct mbuf *m)
57126239Smlaier{
58126239Smlaier	struct m_tag *mtag = m_tag_find(m, PACKET_TAG_DIVERT, NULL);
59126239Smlaier	return mtag ? divert_cookie(mtag) : 0;
60126239Smlaier}
61126239Smlaier
62126239Smlaier/*
63126239Smlaier * Return the divert info associated with the mbuf; if any.
64126239Smlaier */
65126239Smlaierstatic __inline u_int32_t
66126239Smlaierdivert_info(struct m_tag *mtag)
67126239Smlaier{
68126239Smlaier	return ((struct divert_tag *)(mtag+1))->info;
69126239Smlaier}
70126239Smlaierstatic __inline u_int32_t
71126239Smlaierdivert_find_info(struct mbuf *m)
72126239Smlaier{
73126239Smlaier	struct m_tag *mtag = m_tag_find(m, PACKET_TAG_DIVERT, NULL);
74126239Smlaier	return mtag ? divert_info(mtag) : 0;
75126239Smlaier}
76126239Smlaier
77126239Smlaierextern	void div_init(void);
78126239Smlaierextern	void div_input(struct mbuf *, int);
79126239Smlaierextern	void div_ctlinput(int, struct sockaddr *, void *);
80126239Smlaierextern	void divert_packet(struct mbuf *m, int incoming);
81126239Smlaierextern	struct mbuf *divert_clone(struct mbuf *);
82126239Smlaierextern struct pr_usrreqs div_usrreqs;
83126239Smlaier#endif /* _NETINET_IP_DIVERT_H_ */
84