Coverage Report

Created: 2026-08-31 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/haproxy/include/haproxy/sock.h
Line
Count
Source
1
/*
2
 * include/haproxy/sock.h
3
 * This file contains declarations for native (BSD-compatible) sockets.
4
 *
5
 * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation, version 2.1
10
 * exclusively.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20
 */
21
22
#ifndef _HAPROXY_SOCK_H
23
#define _HAPROXY_SOCK_H
24
25
#include <sys/socket.h>
26
#include <sys/types.h>
27
28
#include <haproxy/api.h>
29
#include <haproxy/connection-t.h>
30
#include <haproxy/listener-t.h>
31
#include <haproxy/protocol-t.h>
32
#include <haproxy/sock-t.h>
33
34
int sock_create_server_socket(struct connection *conn, struct proxy *be,
35
                              enum proto_type proto_type, int sock_type, int *stream_err);
36
void sock_enable(struct receiver *rx);
37
void sock_disable(struct receiver *rx);
38
void sock_unbind(struct receiver *rx);
39
int sock_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir);
40
int sock_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir);
41
int sock_get_old_sockets(const char *unixsocket);
42
int sock_find_compatible_fd(const struct receiver *rx);
43
void sock_drop_unused_old_sockets();
44
int sock_accepting_conn(const struct receiver *rx);
45
struct connection *sock_accept_conn(struct listener *l, int *status);
46
void sock_accept_iocb(int fd);
47
void sock_conn_ctrl_init(struct connection *conn);
48
void sock_conn_ctrl_close(struct connection *conn);
49
int sock_conn_get_opt(const struct connection *conn, int level, int optname, void *buf, int size);
50
void sock_conn_iocb(int fd);
51
int sock_conn_check(struct connection *conn);
52
int sock_drain(struct connection *conn);
53
int sock_check_events(struct connection *conn, int event_type);
54
void sock_ignore_events(struct connection *conn, int event_type);
55
int _sock_supports_reuseport(const struct proto_fam *fam, int type, int protocol);
56
57
/* Sets tos sockopt on socket depending on addr target family */
58
static inline void sock_set_tos(int fd, struct sockaddr_storage *addr, int tos)
59
0
{
60
0
#ifdef IP_TOS
61
0
  if (addr->ss_family == AF_INET)
62
0
    setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
63
0
#endif
64
0
#ifdef IPV6_TCLASS
65
0
  if (addr->ss_family == AF_INET6) {
66
0
    if (IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)addr)->sin6_addr))
67
      /* v4-mapped addresses need IP_TOS */
68
0
      setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
69
0
    else
70
0
      setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos));
71
0
  }
72
0
#endif
73
0
}
Unexecuted instantiation: debug.c:sock_set_tos
Unexecuted instantiation: fd.c:sock_set_tos
Unexecuted instantiation: haproxy.c:sock_set_tos
Unexecuted instantiation: http_htx.c:sock_set_tos
Unexecuted instantiation: limits.c:sock_set_tos
Unexecuted instantiation: listener.c:sock_set_tos
Unexecuted instantiation: log.c:sock_set_tos
Unexecuted instantiation: mworker.c:sock_set_tos
Unexecuted instantiation: peers.c:sock_set_tos
Unexecuted instantiation: pool.c:sock_set_tos
Unexecuted instantiation: proto_sockpair.c:sock_set_tos
Unexecuted instantiation: protocol.c:sock_set_tos
Unexecuted instantiation: proxy.c:sock_set_tos
Unexecuted instantiation: resolvers.c:sock_set_tos
Unexecuted instantiation: ring.c:sock_set_tos
Unexecuted instantiation: sample.c:sock_set_tos
Unexecuted instantiation: server.c:sock_set_tos
Unexecuted instantiation: session.c:sock_set_tos
Unexecuted instantiation: sink.c:sock_set_tos
Unexecuted instantiation: sock.c:sock_set_tos
Unexecuted instantiation: sock_inet.c:sock_set_tos
Unexecuted instantiation: stats-proxy.c:sock_set_tos
Unexecuted instantiation: stats.c:sock_set_tos
Unexecuted instantiation: stconn.c:sock_set_tos
Unexecuted instantiation: stick_table.c:sock_set_tos
Unexecuted instantiation: stream.c:sock_set_tos
Unexecuted instantiation: tcp_rules.c:sock_set_tos
Unexecuted instantiation: tcpcheck.c:sock_set_tos
Unexecuted instantiation: thread.c:sock_set_tos
Unexecuted instantiation: tools.c:sock_set_tos
Unexecuted instantiation: trace.c:sock_set_tos
Unexecuted instantiation: vars.c:sock_set_tos
Unexecuted instantiation: activity.c:sock_set_tos
Unexecuted instantiation: applet.c:sock_set_tos
Unexecuted instantiation: backend.c:sock_set_tos
Unexecuted instantiation: cfgparse-listen.c:sock_set_tos
Unexecuted instantiation: cfgparse.c:sock_set_tos
Unexecuted instantiation: channel.c:sock_set_tos
Unexecuted instantiation: check.c:sock_set_tos
Unexecuted instantiation: cli.c:sock_set_tos
Unexecuted instantiation: connection.c:sock_set_tos
Unexecuted instantiation: dns.c:sock_set_tos
Unexecuted instantiation: dns_ring.c:sock_set_tos
Unexecuted instantiation: errors.c:sock_set_tos
Unexecuted instantiation: extcheck.c:sock_set_tos
Unexecuted instantiation: filters.c:sock_set_tos
Unexecuted instantiation: flt_decomp.c:sock_set_tos
Unexecuted instantiation: flt_http_comp.c:sock_set_tos
Unexecuted instantiation: frontend.c:sock_set_tos
Unexecuted instantiation: haterm.c:sock_set_tos
Unexecuted instantiation: http_ana.c:sock_set_tos
Unexecuted instantiation: http_ext.c:sock_set_tos
Unexecuted instantiation: http_fetch.c:sock_set_tos
Unexecuted instantiation: http_rules.c:sock_set_tos
Unexecuted instantiation: mux_spop.c:sock_set_tos
Unexecuted instantiation: pattern.c:sock_set_tos
Unexecuted instantiation: payload.c:sock_set_tos
Unexecuted instantiation: proto_rhttp.c:sock_set_tos
Unexecuted instantiation: queue.c:sock_set_tos
Unexecuted instantiation: stats-html.c:sock_set_tos
Unexecuted instantiation: stats-json.c:sock_set_tos
Unexecuted instantiation: cache.c:sock_set_tos
Unexecuted instantiation: cfgparse-global.c:sock_set_tos
Unexecuted instantiation: compression.c:sock_set_tos
Unexecuted instantiation: fcgi-app.c:sock_set_tos
Unexecuted instantiation: flt_spoe.c:sock_set_tos
Unexecuted instantiation: proto_tcp.c:sock_set_tos
74
75
/* Sets mark sockopt on socket */
76
static inline void sock_set_mark(int fd, sa_family_t sock_family, int mark)
77
0
{
78
0
  if ((sock_family == AF_INET) || (sock_family == AF_INET6)) {
79
0
#if defined(SO_MARK)
80
0
    setsockopt(fd, SOL_SOCKET, SO_MARK, &mark, sizeof(mark));
81
/* FreeBSD */
82
#elif defined(SO_USER_COOKIE)
83
    setsockopt(fd, SOL_SOCKET, SO_USER_COOKIE, &mark, sizeof(mark));
84
/* OpenBSD */
85
#elif defined(SO_RTABLE)
86
    setsockopt(fd, SOL_SOCKET, SO_RTABLE, &mark, sizeof(mark));
87
#endif
88
0
  }
89
0
}
Unexecuted instantiation: debug.c:sock_set_mark
Unexecuted instantiation: fd.c:sock_set_mark
Unexecuted instantiation: haproxy.c:sock_set_mark
Unexecuted instantiation: http_htx.c:sock_set_mark
Unexecuted instantiation: limits.c:sock_set_mark
Unexecuted instantiation: listener.c:sock_set_mark
Unexecuted instantiation: log.c:sock_set_mark
Unexecuted instantiation: mworker.c:sock_set_mark
Unexecuted instantiation: peers.c:sock_set_mark
Unexecuted instantiation: pool.c:sock_set_mark
Unexecuted instantiation: proto_sockpair.c:sock_set_mark
Unexecuted instantiation: protocol.c:sock_set_mark
Unexecuted instantiation: proxy.c:sock_set_mark
Unexecuted instantiation: resolvers.c:sock_set_mark
Unexecuted instantiation: ring.c:sock_set_mark
Unexecuted instantiation: sample.c:sock_set_mark
Unexecuted instantiation: server.c:sock_set_mark
Unexecuted instantiation: session.c:sock_set_mark
Unexecuted instantiation: sink.c:sock_set_mark
Unexecuted instantiation: sock.c:sock_set_mark
Unexecuted instantiation: sock_inet.c:sock_set_mark
Unexecuted instantiation: stats-proxy.c:sock_set_mark
Unexecuted instantiation: stats.c:sock_set_mark
Unexecuted instantiation: stconn.c:sock_set_mark
Unexecuted instantiation: stick_table.c:sock_set_mark
Unexecuted instantiation: stream.c:sock_set_mark
Unexecuted instantiation: tcp_rules.c:sock_set_mark
Unexecuted instantiation: tcpcheck.c:sock_set_mark
Unexecuted instantiation: thread.c:sock_set_mark
Unexecuted instantiation: tools.c:sock_set_mark
Unexecuted instantiation: trace.c:sock_set_mark
Unexecuted instantiation: vars.c:sock_set_mark
Unexecuted instantiation: activity.c:sock_set_mark
Unexecuted instantiation: applet.c:sock_set_mark
Unexecuted instantiation: backend.c:sock_set_mark
Unexecuted instantiation: cfgparse-listen.c:sock_set_mark
Unexecuted instantiation: cfgparse.c:sock_set_mark
Unexecuted instantiation: channel.c:sock_set_mark
Unexecuted instantiation: check.c:sock_set_mark
Unexecuted instantiation: cli.c:sock_set_mark
Unexecuted instantiation: connection.c:sock_set_mark
Unexecuted instantiation: dns.c:sock_set_mark
Unexecuted instantiation: dns_ring.c:sock_set_mark
Unexecuted instantiation: errors.c:sock_set_mark
Unexecuted instantiation: extcheck.c:sock_set_mark
Unexecuted instantiation: filters.c:sock_set_mark
Unexecuted instantiation: flt_decomp.c:sock_set_mark
Unexecuted instantiation: flt_http_comp.c:sock_set_mark
Unexecuted instantiation: frontend.c:sock_set_mark
Unexecuted instantiation: haterm.c:sock_set_mark
Unexecuted instantiation: http_ana.c:sock_set_mark
Unexecuted instantiation: http_ext.c:sock_set_mark
Unexecuted instantiation: http_fetch.c:sock_set_mark
Unexecuted instantiation: http_rules.c:sock_set_mark
Unexecuted instantiation: mux_spop.c:sock_set_mark
Unexecuted instantiation: pattern.c:sock_set_mark
Unexecuted instantiation: payload.c:sock_set_mark
Unexecuted instantiation: proto_rhttp.c:sock_set_mark
Unexecuted instantiation: queue.c:sock_set_mark
Unexecuted instantiation: stats-html.c:sock_set_mark
Unexecuted instantiation: stats-json.c:sock_set_mark
Unexecuted instantiation: cache.c:sock_set_mark
Unexecuted instantiation: cfgparse-global.c:sock_set_mark
Unexecuted instantiation: compression.c:sock_set_mark
Unexecuted instantiation: fcgi-app.c:sock_set_mark
Unexecuted instantiation: flt_spoe.c:sock_set_mark
Unexecuted instantiation: proto_tcp.c:sock_set_mark
90
91
#endif /* _HAPROXY_SOCK_H */
92
93
/*
94
 * Local variables:
95
 *  c-indent-level: 8
96
 *  c-basic-offset: 8
97
 * End:
98
 */