fixed the longstanding myids memory leak
[strongswan.git] / src / pluto / id.h
1 /* identity representation, as in IKE ID Payloads (RFC 2407 DOI 4.6.2.1)
2 * Copyright (C) 1999-2001 D. Hugh Redelmeier
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * RCSID $Id$
15 */
16
17 #ifndef _ID_H
18 #define _ID_H
19
20 #include "defs.h"
21
22 struct id {
23 int kind; /* ID_* value */
24 ip_address ip_addr; /* ID_IPV4_ADDR, ID_IPV6_ADDR */
25 chunk_t name; /* ID_FQDN, ID_USER_FQDN (with @) */
26 /* ID_KEY_ID, ID_DER_ASN_DN */
27 };
28
29 extern void init_id(void);
30 extern void free_id(void);
31 extern const struct id empty_id; /* ID_NONE */
32
33 enum myid_state {
34 MYID_UNKNOWN, /* not yet figured out */
35 MYID_HOSTNAME, /* our current hostname */
36 MYID_IP, /* our default IP address */
37 MYID_SPECIFIED /* as specified by ipsec.conf */
38 };
39
40 extern enum myid_state myid_state;
41 extern struct id myids[MYID_SPECIFIED+1]; /* %myid */
42 extern char *myid_str[MYID_SPECIFIED+1]; /* strings */
43 extern void set_myid(enum myid_state s, char *);
44 extern void show_myid_status(void);
45 #define resolve_myid(id) ((id)->kind == ID_MYID? &myids[myid_state] : (id))
46 extern void set_myFQDN(void);
47
48 extern err_t atoid(char *src, struct id *id, bool myid_ok);
49 extern int keyidtoa(char *dst, size_t dstlen, chunk_t keyid);
50 extern void iptoid(const ip_address *ip, struct id *id);
51 extern int idtoa(const struct id *id, char *dst, size_t dstlen);
52 #define IDTOA_BUF 512
53 extern void escape_metachar(const char *src, char *dst, size_t dstlen);
54 struct end; /* forward declaration of tag (defined in connections.h) */
55 extern void unshare_id_content(struct id *id);
56 extern void free_id_content(struct id *id);
57 extern bool same_id(const struct id *a, const struct id *b);
58 #define MAX_WILDCARDS 15
59 extern bool match_id(const struct id *a, const struct id *b, int *wildcards);
60 extern int id_count_wildcards(const struct id *id);
61 #define id_is_ipaddr(id) ((id)->kind == ID_IPV4_ADDR || (id)->kind == ID_IPV6_ADDR)
62
63 struct isakmp_ipsec_id; /* forward declaration of tag (defined in packet.h) */
64 extern void
65 build_id_payload(struct isakmp_ipsec_id *hd, chunk_t *tl, struct end *end);
66
67 #endif /* _ID_H */