1b26fb63fSBjoern A. Zeeb /*- 2b26fb63fSBjoern A. Zeeb * SPDX-License-Identifier: BSD-2-Clause 3b26fb63fSBjoern A. Zeeb * 4b26fb63fSBjoern A. Zeeb * Copyright (c) 2020-2021 The FreeBSD Foundation 5b26fb63fSBjoern A. Zeeb * 6b26fb63fSBjoern A. Zeeb * This software was developed by Björn Zeeb under sponsorship from 7b26fb63fSBjoern A. Zeeb * the FreeBSD Foundation. 8b26fb63fSBjoern A. Zeeb * 9b26fb63fSBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without 10b26fb63fSBjoern A. Zeeb * modification, are permitted provided that the following conditions 11b26fb63fSBjoern A. Zeeb * are met: 12b26fb63fSBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright 13b26fb63fSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer. 14b26fb63fSBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright 15b26fb63fSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the 16b26fb63fSBjoern A. Zeeb * documentation and/or other materials provided with the distribution. 17b26fb63fSBjoern A. Zeeb * 18b26fb63fSBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19b26fb63fSBjoern A. Zeeb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20b26fb63fSBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21b26fb63fSBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22b26fb63fSBjoern A. Zeeb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23b26fb63fSBjoern A. Zeeb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24b26fb63fSBjoern A. Zeeb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25b26fb63fSBjoern A. Zeeb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26b26fb63fSBjoern A. Zeeb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27b26fb63fSBjoern A. Zeeb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28b26fb63fSBjoern A. Zeeb * SUCH DAMAGE. 29b26fb63fSBjoern A. Zeeb * 30b26fb63fSBjoern A. Zeeb * $FreeBSD$ 31b26fb63fSBjoern A. Zeeb */ 32b26fb63fSBjoern A. Zeeb 33*307f78f3SVladimir Kondratyev #ifndef _LINUXKPI_LINUX_IP_H 34*307f78f3SVladimir Kondratyev #define _LINUXKPI_LINUX_IP_H 35b26fb63fSBjoern A. Zeeb 36b26fb63fSBjoern A. Zeeb #include <sys/types.h> 37b26fb63fSBjoern A. Zeeb 384ddc0079SBjoern A. Zeeb #include <netinet/in.h> 39b26fb63fSBjoern A. Zeeb #include <netinet/ip.h> 40b26fb63fSBjoern A. Zeeb #include <machine/in_cksum.h> 41b26fb63fSBjoern A. Zeeb 42b26fb63fSBjoern A. Zeeb #include <linux/skbuff.h> 43b26fb63fSBjoern A. Zeeb 44b26fb63fSBjoern A. Zeeb /* (u) unconfirmed structure field names; using FreeBSD's meanwhile. */ 45b26fb63fSBjoern A. Zeeb struct iphdr { 46b26fb63fSBjoern A. Zeeb uint8_t ip_hl:4, ip_ver:4; /* (u) */ 47b26fb63fSBjoern A. Zeeb uint8_t ip_tos; /* (u) */ 48b26fb63fSBjoern A. Zeeb uint16_t ip_len; /* (u) */ 49b26fb63fSBjoern A. Zeeb uint16_t id; 50b26fb63fSBjoern A. Zeeb uint16_t ip_off; /* (u) */ 51b26fb63fSBjoern A. Zeeb uint8_t ip_ttl; /* (u) */ 52b26fb63fSBjoern A. Zeeb uint8_t protocol; 53b26fb63fSBjoern A. Zeeb uint16_t check; 54b26fb63fSBjoern A. Zeeb uint32_t saddr; 55b26fb63fSBjoern A. Zeeb uint32_t daddr; 56b26fb63fSBjoern A. Zeeb }; 57b26fb63fSBjoern A. Zeeb 58b26fb63fSBjoern A. Zeeb static __inline struct iphdr * 59b26fb63fSBjoern A. Zeeb ip_hdr(struct sk_buff *skb) 60b26fb63fSBjoern A. Zeeb { 61b26fb63fSBjoern A. Zeeb 62b26fb63fSBjoern A. Zeeb return (struct iphdr *)skb_network_header(skb); 63b26fb63fSBjoern A. Zeeb } 64b26fb63fSBjoern A. Zeeb 65b26fb63fSBjoern A. Zeeb static __inline void 66b26fb63fSBjoern A. Zeeb ip_send_check(struct iphdr *iph) 67b26fb63fSBjoern A. Zeeb { 68b26fb63fSBjoern A. Zeeb 69b26fb63fSBjoern A. Zeeb /* Clear the checksum before computing! */ 70b26fb63fSBjoern A. Zeeb iph->check = 0; 71b26fb63fSBjoern A. Zeeb /* An IPv4 header is the same everywhere even if names differ. */ 72b26fb63fSBjoern A. Zeeb iph->check = in_cksum_hdr((const void *)iph); 73b26fb63fSBjoern A. Zeeb } 74b26fb63fSBjoern A. Zeeb 75*307f78f3SVladimir Kondratyev #endif /* _LINUXKPI_LINUX_IP_H */ 76