ip_divert.h revision 136714
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 136714 2004-10-19 21:14:57Z andre $ 33126239Smlaier */ 34126239Smlaier 35126239Smlaier#ifndef _NETINET_IP_DIVERT_H_ 36126239Smlaier#define _NETINET_IP_DIVERT_H_ 37126239Smlaier 38126239Smlaier/* 39136714Sandre * Sysctl declaration. 40136714Sandre */ 41136714Sandre#ifdef SYSCTL_DECL 42136714SandreSYSCTL_DECL(_net_inet_divert); 43136714Sandre#endif 44136714Sandre 45136714Sandre/* 46126239Smlaier * Divert socket definitions. 47126239Smlaier */ 48126239Smlaierstruct divert_tag { 49126239Smlaier u_int32_t info; /* port & flags */ 50126239Smlaier u_int16_t cookie; /* ipfw rule number */ 51126239Smlaier}; 52126239Smlaier 53126239Smlaier/* 54126239Smlaier * Return the divert cookie associated with the mbuf; if any. 55126239Smlaier */ 56126239Smlaierstatic __inline u_int16_t 57126239Smlaierdivert_cookie(struct m_tag *mtag) 58126239Smlaier{ 59126239Smlaier return ((struct divert_tag *)(mtag+1))->cookie; 60126239Smlaier} 61126239Smlaierstatic __inline u_int16_t 62126239Smlaierdivert_find_cookie(struct mbuf *m) 63126239Smlaier{ 64126239Smlaier struct m_tag *mtag = m_tag_find(m, PACKET_TAG_DIVERT, NULL); 65126239Smlaier return mtag ? divert_cookie(mtag) : 0; 66126239Smlaier} 67126239Smlaier 68126239Smlaier/* 69126239Smlaier * Return the divert info associated with the mbuf; if any. 70126239Smlaier */ 71126239Smlaierstatic __inline u_int32_t 72126239Smlaierdivert_info(struct m_tag *mtag) 73126239Smlaier{ 74126239Smlaier return ((struct divert_tag *)(mtag+1))->info; 75126239Smlaier} 76126239Smlaierstatic __inline u_int32_t 77126239Smlaierdivert_find_info(struct mbuf *m) 78126239Smlaier{ 79126239Smlaier struct m_tag *mtag = m_tag_find(m, PACKET_TAG_DIVERT, NULL); 80126239Smlaier return mtag ? divert_info(mtag) : 0; 81126239Smlaier} 82126239Smlaier 83136714Sandretypedef void ip_divert_packet_t(struct mbuf *m, int incoming); 84136714Sandreextern ip_divert_packet_t *ip_divert_ptr; 85136714Sandre 86126239Smlaierextern void div_init(void); 87126239Smlaierextern void div_input(struct mbuf *, int); 88126239Smlaierextern void div_ctlinput(int, struct sockaddr *, void *); 89126239Smlaier#endif /* _NETINET_IP_DIVERT_H_ */ 90