]> git.proxmox.com Git - mirror_frr.git/blob - lib/sockopt.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / sockopt.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Router advertisement
3 * Copyright (C) 1999 Kunihiro Ishiguro
4 */
5
6 #ifndef _ZEBRA_SOCKOPT_H
7 #define _ZEBRA_SOCKOPT_H
8
9 #include "sockunion.h"
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 extern void setsockopt_so_recvbuf(int sock, int size);
16 extern void setsockopt_so_sendbuf(const int sock, int size);
17 extern int getsockopt_so_sendbuf(const int sock);
18 extern int getsockopt_so_recvbuf(const int sock);
19
20 extern int setsockopt_ipv6_pktinfo(int, int);
21 extern int setsockopt_ipv6_multicast_hops(int, int);
22 extern int setsockopt_ipv6_unicast_hops(int, int);
23 extern int setsockopt_ipv6_hoplimit(int, int);
24 extern int setsockopt_ipv6_multicast_loop(int, int);
25 extern int setsockopt_ipv6_tclass(int, int);
26
27 #define SOPT_SIZE_CMSG_PKTINFO_IPV6() (sizeof(struct in6_pktinfo));
28
29 /*
30 * Size defines for control messages used to get ifindex. We define
31 * values for each method, and define a macro that can be used by code
32 * that is unaware of which method is in use.
33 * These values are without any alignment needed (see CMSG_SPACE in RFC3542).
34 */
35 #if defined(IP_PKTINFO)
36 /* Linux in_pktinfo. */
37 #define SOPT_SIZE_CMSG_PKTINFO_IPV4() (CMSG_SPACE(sizeof(struct in_pktinfo)))
38 /* XXX This should perhaps be defined even if IP_PKTINFO is not. */
39 #define SOPT_SIZE_CMSG_PKTINFO(af) \
40 ((af == AF_INET) ? SOPT_SIZE_CMSG_PKTINFO_IPV4() \
41 : SOPT_SIZE_CMSG_PKTINFO_IPV6()
42 #endif /* IP_PKTINFO */
43
44 #if defined(IP_RECVIF)
45 /* BSD/Solaris */
46
47 #define SOPT_SIZE_CMSG_RECVIF_IPV4() (sizeof(struct sockaddr_dl))
48 #endif /* IP_RECVIF */
49
50 /* SOPT_SIZE_CMSG_IFINDEX_IPV4 - portable type */
51 #if defined(SOPT_SIZE_CMSG_PKTINFO)
52 #define SOPT_SIZE_CMSG_IFINDEX_IPV4() SOPT_SIZE_CMSG_PKTINFO_IPV4()
53 #elif defined(SOPT_SIZE_CMSG_RECVIF_IPV4)
54 #define SOPT_SIZE_CMSG_IFINDEX_IPV4() SOPT_SIZE_CMSG_RECVIF_IPV4()
55 #else /* Nothing available */
56 #define SOPT_SIZE_CMSG_IFINDEX_IPV4() (sizeof(char *))
57 #endif /* SOPT_SIZE_CMSG_IFINDEX_IPV4 */
58
59 #define SOPT_SIZE_CMSG_IFINDEX(af) \
60 (((af) == AF_INET) : SOPT_SIZE_CMSG_IFINDEX_IPV4() \
61 ? SOPT_SIZE_CMSG_PKTINFO_IPV6())
62
63 extern int setsockopt_ipv4_multicast_if(int sock, struct in_addr if_addr,
64 ifindex_t ifindex);
65 extern int setsockopt_ipv4_multicast(int sock, int optname,
66 struct in_addr if_addr,
67 unsigned int mcast_addr,
68 ifindex_t ifindex);
69 extern int setsockopt_ipv4_multicast_loop(int sock, uint8_t val);
70
71 extern int setsockopt_ipv4_tos(int sock, int tos);
72
73 /* Ask for, and get, ifindex, by whatever method is supported. */
74 extern int setsockopt_ifindex(int, int, ifindex_t);
75 extern ifindex_t getsockopt_ifindex(int, struct msghdr *);
76
77 /* swab the fields in iph between the host order and system order expected
78 * for IP_HDRINCL.
79 */
80 extern void sockopt_iphdrincl_swab_htosys(struct ip *iph);
81 extern void sockopt_iphdrincl_swab_systoh(struct ip *iph);
82
83 extern int sockopt_tcp_rtt(int);
84
85 /*
86 * TCP MD5 signature option. This option allows TCP MD5 to be enabled on
87 * addresses.
88 *
89 * sock
90 * Socket to enable option on.
91 *
92 * su
93 * Sockunion specifying address to enable option on.
94 *
95 * password
96 * MD5 auth password
97 */
98 extern int sockopt_tcp_signature(int sock, union sockunion *su,
99 const char *password);
100
101 /*
102 * Extended TCP MD5 signature option. This option allows TCP MD5 to be enabled
103 * on prefixes.
104 *
105 * sock
106 * Socket to enable option on.
107 *
108 * su
109 * Sockunion specifying address (or prefix) to enable option on.
110 *
111 * prefixlen
112 * 0 - su is an address; fall back to non-extended mode
113 * Else - su is a prefix; prefixlen is the mask length
114 *
115 * password
116 * MD5 auth password
117 */
118 extern int sockopt_tcp_signature_ext(int sock, union sockunion *su,
119 uint16_t prefixlen, const char *password);
120
121 /*
122 * set TCP max segment size. This option allows user to configure
123 * max segment size for TCP session
124 *
125 * sock
126 * Socket to enable option on.
127 *
128 * tcp_maxseg
129 * value used for TCP segment size negotiation during SYN
130 */
131 extern int sockopt_tcp_mss_set(int sock, int tcp_maxseg);
132
133 /*
134 * get TCP max segment size. This option allows user to get
135 * the segment size for TCP session
136 *
137 * sock
138 * Socket to get max segement size.
139 */
140 extern int sockopt_tcp_mss_get(int sock);
141
142 /*
143 * Configure TCP keepalive for a given socket
144 *
145 * sock
146 * Socket to enable keepalive option on.
147 *
148 * keepalive_idle
149 * number of seconds a connection needs to be idle
150 * before sending out keep-alive proves
151 *
152 * keepalive_intvl
153 * number of seconds between TCP keep-alive probes
154 *
155 * keepalive_probes
156 * max number of probers to send before giving up
157 * and killing tcp connection
158 */
159 extern int setsockopt_tcp_keepalive(int sock, uint16_t keepalive_idle,
160 uint16_t keepalive_intvl,
161 uint16_t keepalive_probes);
162
163 #ifdef __cplusplus
164 }
165 #endif
166
167 #endif /*_ZEBRA_SOCKOPT_H */