]> git.proxmox.com Git - mirror_frr.git/blame - lib/sockunion.h
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / sockunion.h
CommitLineData
718e3744 1/*
2 * Socket union header.
3 * Copyright (c) 1997 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
896014f4
DL
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 20 */
21
22#ifndef _ZEBRA_SOCKUNION_H
23#define _ZEBRA_SOCKUNION_H
24
ed40466a 25#include "privs.h"
b892f1dd 26#include "if.h"
fe6c7157 27#ifdef __OpenBSD__
d3e2c74a
RW
28#include <netmpls/mpls.h>
29#endif
ed40466a 30
d62a17ae 31union sockunion {
32 struct sockaddr sa;
33 struct sockaddr_in sin;
34 struct sockaddr_in6 sin6;
fe6c7157 35#ifdef __OpenBSD__
d62a17ae 36 struct sockaddr_mpls smpls;
88ed8379 37 struct sockaddr_rtlabel rtlabel;
d3e2c74a 38#endif
718e3744 39};
40
d62a17ae 41enum connect_result { connect_error, connect_success, connect_in_progress };
718e3744 42
43/* Default address family. */
718e3744 44#define AF_INET_UNION AF_INET6
718e3744 45
46/* Sockunion address string length. Same as INET6_ADDRSTRLEN. */
47#define SU_ADDRSTRLEN 46
48
49/* Macro to set link local index to the IPv6 address. For KAME IPv6
50 stack. */
51#ifdef KAME
52#define IN6_LINKLOCAL_IFINDEX(a) ((a).s6_addr[2] << 8 | (a).s6_addr[3])
d62a17ae 53#define SET_IN6_LINKLOCAL_IFINDEX(a, i) \
54 do { \
55 (a).s6_addr[2] = ((i) >> 8) & 0xff; \
56 (a).s6_addr[3] = (i)&0xff; \
57 } while (0)
718e3744 58#else
59#define IN6_LINKLOCAL_IFINDEX(a)
60#define SET_IN6_LINKLOCAL_IFINDEX(a, i)
61#endif /* KAME */
62
718e3744 63#define sockunion_family(X) (X)->sa.sa_family
64
0c5ed3ed
JBD
65#define sockunion2ip(X) (X)->sin.sin_addr.s_addr
66
718e3744 67/* Prototypes. */
d62a17ae 68extern int str2sockunion(const char *, union sockunion *);
69extern const char *sockunion2str(const union sockunion *, char *, size_t);
70extern int sockunion_cmp(const union sockunion *, const union sockunion *);
71extern int sockunion_same(const union sockunion *, const union sockunion *);
72extern unsigned int sockunion_hash(const union sockunion *);
718e3744 73
95e0999c
TT
74extern size_t family2addrsize(int family);
75extern size_t sockunion_get_addrlen(const union sockunion *);
d7c0a89a
QY
76extern const uint8_t *sockunion_get_addr(const union sockunion *);
77extern void sockunion_set(union sockunion *, int family, const uint8_t *addr,
d62a17ae 78 size_t bytes);
95e0999c 79
d62a17ae 80extern union sockunion *sockunion_str2su(const char *str);
81extern int sockunion_accept(int sock, union sockunion *);
82extern int sockunion_stream_socket(union sockunion *);
83extern int sockopt_reuseaddr(int);
84extern int sockopt_reuseport(int);
85extern int sockopt_v6only(int family, int sock);
86extern int sockunion_bind(int sock, union sockunion *, unsigned short,
87 union sockunion *);
88extern int sockopt_ttl(int family, int sock, int ttl);
89extern int sockopt_minttl(int family, int sock, int minttl);
90extern int sockopt_cork(int sock, int onoff);
ed40466a 91extern int sockopt_mark_default(int sock, int mark, struct zebra_privs_t *);
d62a17ae 92extern int sockunion_socket(const union sockunion *su);
93extern const char *inet_sutop(const union sockunion *su, char *str);
94extern enum connect_result sockunion_connect(int fd, const union sockunion *su,
95 unsigned short port, ifindex_t);
96extern union sockunion *sockunion_getsockname(int);
97extern union sockunion *sockunion_getpeername(int);
98extern union sockunion *sockunion_dup(const union sockunion *);
99extern void sockunion_free(union sockunion *);
100extern void sockunion_init(union sockunion *);
718e3744 101
718e3744 102#endif /* _ZEBRA_SOCKUNION_H */