File: ip_endpoint.h

package info (click to toggle)
libreswan 4.3-1%2Bdeb11u4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 62,688 kB
  • sloc: ansic: 108,293; sh: 25,973; xml: 11,756; python: 10,230; makefile: 1,580; javascript: 1,353; yacc: 825; sed: 647; perl: 584; lex: 159; awk: 156
file content (138 lines) | stat: -rw-r--r-- 4,238 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* ip endpoint (address + port), for libreswan
 *
 * Copyright (C) 2019-2020 Andrew Cagney <cagney@gnu.org>
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Library General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <https://www.gnu.org/licenses/lgpl-2.1.txt>.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 * License for more details.
 *
 */

#ifndef IP_ENDPOINT_H
#define IP_ENDPOINT_H

#include <stdbool.h>

#include "chunk.h"
#include "err.h"
#include "ip_address.h"
#include "ip_port.h"
#include "ip_protoport.h"

struct jambuf;
struct ip_protocol;

typedef struct {
	/*
	 * Index into the struct ip_info array; must be stream
	 * friendly.
	 */
	unsigned version; /* 0, 4, 6 */
	/*
	 * We need something that makes static IPv4 initializers possible
	 * (struct in_addr requires htonl() which is run-time only).
	 */
	struct ip_bytes bytes;
	/*
	 * In pluto "0" denotes all ports (or, in the context of an
	 * endpoint, is that none?).
	 */
	int hport;
	unsigned ipproto;
	bool is_endpoint;
} ip_endpoint;

#define PRI_ENDPOINT "%s (version=%d hport=%u ipproto=%u is_endpoint=%s)"
#define pri_endpoint(A, B)						\
		str_endpoint(A, B),					\
		(A)->version,						\
		(A)->hport,						\
		(A)->ipproto,						\
		bool_str((A)->is_endpoint)

void pexpect_endpoint(const ip_endpoint *e, const char *t, where_t where);
#define pendpoint(E) pexpect_endpoint(E, #E, HERE)

/*
 * Constructors.
 */

ip_endpoint endpoint_from_address_protocol_port(const ip_address *address,
						const struct ip_protocol *protocol,
						ip_port port);
ip_endpoint endpoint3(const struct ip_protocol *protocol,
		      const ip_address *address, ip_port port);

/*
 * Formatting
 *
 * Endpoint formatting is always "cooked".  For instance, the address
 * "::1" is printed as "[::1]:PORT" (raw would print it as
 * "[0:0....:0]:PORT"
 *
 * XXX: sizeof("") includes '\0'.  What's an extra few bytes between
 * friends?
 */

typedef struct {
	char buf[sizeof("[") + sizeof(address_buf) + sizeof("]:65535")];
} endpoint_buf;

const char *str_endpoint(const ip_endpoint *, endpoint_buf *);
size_t jam_endpoint(struct jambuf *, const ip_endpoint*);
const char *str_sensitive_endpoint(const ip_endpoint *, endpoint_buf *);
size_t jam_sensitive_endpoint(struct jambuf *, const ip_endpoint*);

typedef struct {
	char buf[sizeof(endpoint_buf) + sizeof("--UNKNOWN--UNKNOWN-->") + sizeof(endpoint_buf)];
} endpoints_buf;

size_t jam_endpoints(struct jambuf *jambuf, const ip_endpoint *src, const ip_endpoint *dst);
const char *str_endpoints(const ip_endpoint *src, const ip_endpoint *dst, endpoints_buf *buf);

/*
 * Logic
 */

bool endpoint_eq(const ip_endpoint *l, const ip_endpoint *r);
bool endpoint_address_eq(const ip_endpoint *endpoint, const ip_address *address);

/*
 * Magic values.
 *
 * XXX: While the headers call the all-zero address "ANY" (INADDR_ANY,
 * IN6ADDR_ANY_INIT), the headers also refer to the IPv6 value as
 * unspecified (for instance IN6_IS_ADDR_UNSPECIFIED()) leaving the
 * term "unspecified" underspecified.
 *
 * Consequently an AF_UNSPEC address (i.e., uninitialized or unset),
 * is identified by *_unset().
 */

extern const ip_endpoint unset_endpoint;
bool endpoint_is_unset(const ip_endpoint *endpoint);

const struct ip_info *endpoint_type(const ip_endpoint *endpoint);
const struct ip_protocol *endpoint_protocol(const ip_endpoint *endpoint);

bool endpoint_is_any(const ip_endpoint *endpoint);
bool endpoint_is_specified(const ip_endpoint *endpoint);

ip_address endpoint_address(const ip_endpoint *endpoint);
ip_endpoint set_endpoint_address(const ip_endpoint *endpoint,
				 const ip_address) MUST_USE_RESULT;

ip_port endpoint_port(const ip_endpoint *endpoint);
ip_endpoint set_endpoint_port(const ip_endpoint *endpoint,
			      ip_port port) MUST_USE_RESULT;
void update_endpoint_port(ip_endpoint *endpoint, ip_port port);

int endpoint_hport(const ip_endpoint *endpoint);

#endif