1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Based on include/net/ip.h
4 * Authors: Ross Biro
5 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
6 * Alan Cox, <gw4pts@gw4pts.ampr.org>
7 *
8 * Changes:
9 * Mike McLagan : Routing by source
10 *
11 * Based on include/net/protocol.h
12 * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
13 *
14 * Changes:
15 * Alan Cox : Added a name field and a frag handler
16 * field for later.
17 * Alan Cox : Cleaned up, and sorted types.
18 * Pedro Roque : inet6 protocols
19 *
20 * NewIP INET
21 * An implementation of the TCP/IP protocol suite for the LINUX
22 * operating system. NewIP INET is implemented using the BSD Socket
23 * interface as the means of communication with the user level.
24 *
25 * Definitions for the NewIP module.
26 */
27 #ifndef _NET_NEWIP_H
28 #define _NET_NEWIP_H
29
30 #include <net/dst.h>
31 #include <net/protocol.h>
32 #include <linux/errno.h>
33 #include <linux/netdevice.h>
34 #include <linux/skbuff.h>
35 #include <linux/socket.h>
36 #include <linux/sockios.h>
37 #include <linux/types.h>
38 #include <linux/printk.h>
39 #include <linux/nip.h>
40
41 #include <net/tcp.h>
42 #include <uapi/linux/nip_addr.h>
43 #include "if_ninet.h"
44 #include "flow_nip.h"
45
46 #define NIP_MAX_SOCKET_NUM 1024
47
48 struct ninet_protocol {
49 void (*early_demux)(struct sk_buff *skb);
50
51 int (*handler)(struct sk_buff *skb);
52
53 void (*err_handler)(struct sk_buff *skb,
54 struct ninet_skb_parm *opt,
55 u8 type, u8 code, int offset, __be32 info);
56 unsigned int flags;
57 };
58
59 #define nipcb(skb) ((struct ninet_skb_parm *)&(TCP_SKB_CB(skb)->header.hnip))
60
61 extern const struct ninet_protocol __rcu *ninet_protos[MAX_INET_PROTOS];
62 extern const struct proto_ops ninet_dgram_ops;
63 extern const struct proto_ops ninet_stream_ops;
64 extern struct neigh_table nnd_tbl;
65
66 int tcp_nip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl);
67 void tcp_nip_actual_send_reset(struct sock *sk, struct sk_buff *skb, u32 seq,
68 u32 ack_seq, u32 win, int rst, u32 priority);
69 int nip_rcv(struct sk_buff *skb, struct net_device *dev,
70 struct packet_type *pt, struct net_device *orig_dev);
71 struct nip_rt_info *nip_dst_alloc(struct net *net, struct net_device *dev,
72 int flags);
73
nip_addr_and_ifindex_eq(const struct nip_addr * a1,const struct nip_addr * a2,int ifindex1,int ifindex2)74 static inline bool nip_addr_and_ifindex_eq(const struct nip_addr *a1,
75 const struct nip_addr *a2, int ifindex1, int ifindex2)
76 {
77 return (a1->bitlen == a2->bitlen) && (a1->bitlen <= NIP_ADDR_BIT_LEN_MAX) &&
78 (memcmp(&a1->v.u, &a2->v.u, a1->bitlen >> 3) == 0) && (ifindex1 == ifindex2);
79 };
80
nip_addr_eq(const struct nip_addr * a1,const struct nip_addr * a2)81 static inline bool nip_addr_eq(const struct nip_addr *a1,
82 const struct nip_addr *a2)
83 {
84 return (a1->bitlen == a2->bitlen) && (a1->bitlen <= NIP_ADDR_BIT_LEN_MAX) &&
85 (memcmp(&a1->v.u, &a2->v.u, a1->bitlen >> 3) == 0);
86 };
87
nip_addr_hash(const struct nip_addr * a)88 static inline u32 nip_addr_hash(const struct nip_addr *a)
89 {
90 u32 tmp[4];
91 u8 len = a->bitlen >> 3;
92
93 /* set unused bit to 0 */
94 memset(tmp, 0, NIP_ADDR_BIT_LEN_16);
95 memcpy(tmp, &a->v.u,
96 len > NIP_ADDR_BIT_LEN_16 ? NIP_ADDR_BIT_LEN_16 : len);
97
98 return (__force u32)(tmp[0] ^ tmp[1] ^ tmp[2] ^ tmp[3]);
99 }
100
101 int nip_send_skb(struct sk_buff *skb);
102
103 void ninet_destroy_sock(struct sock *sk);
104 int nip_datagram_dst_update(struct sock *sk, bool fix_sk_saddr);
105 int ninet_add_protocol(const struct ninet_protocol *prot, unsigned char protocol);
106 int ninet_del_protocol(const struct ninet_protocol *prot, unsigned char protocol);
107 int ninet_register_protosw(struct inet_protosw *p);
108 void ninet_unregister_protosw(struct inet_protosw *p);
109 int nip_input(struct sk_buff *skb);
110 int nip_output(struct net *net, struct sock *sk, struct sk_buff *skb);
111 int nip_forward(struct sk_buff *skb);
112
113 unsigned int tcp_nip_sync_mss(struct sock *sk, u32 pmtu);
114 unsigned int tcp_nip_current_mss(struct sock *sk);
115 int tcp_nip_send_mss(struct sock *sk, int *size_goal, int flags);
116
117 struct nip_addr *nip_nexthop(struct nip_rt_info *rt, struct nip_addr *daddr);
118 struct dst_entry *nip_sk_dst_lookup_flow(struct sock *sk, struct flow_nip *fln);
119 struct dst_entry *nip_dst_lookup_flow(struct net *net, const struct sock *sk,
120 struct flow_nip *fln,
121 const struct nip_addr *final_dst);
122 u_char *nip_get_mac(struct nip_addr *nipaddr, struct net_device *dev);
123 struct net_device *nip_get_defaultdev(void);
124 int nip_init_dev(void);
125
126 int _nip_udp_output(struct sock *sk, void *from, int datalen,
127 int transhdrlen, const struct nip_addr *saddr,
128 ushort sport, const struct nip_addr *daddr,
129 ushort dport, struct dst_entry *dst);
130
131 /* functions defined in nip_sockglue.c */
132 int nip_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval,
133 unsigned int optlen);
134 int nip_getsockopt(struct sock *sk, int level,
135 int optname, char __user *optval, int __user *optlen);
136
137 /* functions defined in nip_addrconf.c */
138 int nip_addrconf_get_ifaddr(struct net *net, unsigned int cmd, void __user *arg);
139
140 #endif
141