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
31*307f78f3SVladimir Kondratyev #ifndef _LINUXKPI_LINUX_IP_H
32*307f78f3SVladimir Kondratyev #define _LINUXKPI_LINUX_IP_H
33b26fb63fSBjoern A. Zeeb
34b26fb63fSBjoern A. Zeeb #include <sys/types.h>
35b26fb63fSBjoern A. Zeeb
364ddc0079SBjoern A. Zeeb #include <netinet/in.h>
37b26fb63fSBjoern A. Zeeb #include <netinet/ip.h>
38b26fb63fSBjoern A. Zeeb #include <machine/in_cksum.h>
39b26fb63fSBjoern A. Zeeb
40b26fb63fSBjoern A. Zeeb #include <linux/skbuff.h>
41b26fb63fSBjoern A. Zeeb
42b26fb63fSBjoern A. Zeeb /* (u) unconfirmed structure field names; using FreeBSD's meanwhile. */
43b26fb63fSBjoern A. Zeeb struct iphdr {
44b26fb63fSBjoern A. Zeeb uint8_t ip_hl:4, ip_ver:4; /* (u) */
45b26fb63fSBjoern A. Zeeb uint8_t ip_tos; /* (u) */
46b26fb63fSBjoern A. Zeeb uint16_t ip_len; /* (u) */
47b26fb63fSBjoern A. Zeeb uint16_t id;
48b26fb63fSBjoern A. Zeeb uint16_t ip_off; /* (u) */
49b26fb63fSBjoern A. Zeeb uint8_t ip_ttl; /* (u) */
50b26fb63fSBjoern A. Zeeb uint8_t protocol;
51b26fb63fSBjoern A. Zeeb uint16_t check;
52b26fb63fSBjoern A. Zeeb uint32_t saddr;
53b26fb63fSBjoern A. Zeeb uint32_t daddr;
54b26fb63fSBjoern A. Zeeb };
55b26fb63fSBjoern A. Zeeb
56b26fb63fSBjoern A. Zeeb static __inline struct iphdr *
ip_hdr(struct sk_buff * skb)57b26fb63fSBjoern A. Zeeb ip_hdr(struct sk_buff *skb)
58b26fb63fSBjoern A. Zeeb {
59b26fb63fSBjoern A. Zeeb
60b26fb63fSBjoern A. Zeeb return (struct iphdr *)skb_network_header(skb);
61b26fb63fSBjoern A. Zeeb }
62b26fb63fSBjoern A. Zeeb
63b26fb63fSBjoern A. Zeeb static __inline void
ip_send_check(struct iphdr * iph)64b26fb63fSBjoern A. Zeeb ip_send_check(struct iphdr *iph)
65b26fb63fSBjoern A. Zeeb {
66b26fb63fSBjoern A. Zeeb
67b26fb63fSBjoern A. Zeeb /* Clear the checksum before computing! */
68b26fb63fSBjoern A. Zeeb iph->check = 0;
69b26fb63fSBjoern A. Zeeb /* An IPv4 header is the same everywhere even if names differ. */
70b26fb63fSBjoern A. Zeeb iph->check = in_cksum_hdr((const void *)iph);
71b26fb63fSBjoern A. Zeeb }
72b26fb63fSBjoern A. Zeeb
73*307f78f3SVladimir Kondratyev #endif /* _LINUXKPI_LINUX_IP_H */
74