summaryrefslogtreecommitdiff
path: root/src/ipaddrcheck_functions.h
blob: 73dd246b6a278ad0caaed088fd398633ac0458db (plain)
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
/*
 * ipaddrcheck_functions.h: macros and prototypes for ipaddrcheck
 *
 * Copyright (C) 2013 Daniil Baturin
 * Copyright (C) 2018 VyOS maintainers and contributors
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifndef IPADDRCHECK_FUNCTIONS_H
#define IPADDRCHECK_FUNCTIONS_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <pcre.h>
#include <libcidr.h>

#define INVALID_PROTO -1

#define RESULT_SUCCESS 1
#define RESULT_FAILURE 0
#define RESULT_INT_ERROR 2

#define IPV4_MULTICAST "224.0.0.0/4"
#define IPV4_LOOPBACK  "127.0.0.0/8"
#define IPV4_LINKLOCAL "169.254.0.0/16"
#define IPV4_UNSPECIFIED "0.0.0.0/0"
#define IPV4_THIS        "0.0.0.0/8"
#define IPV4_RFC1918_A "10.0.0.0/8"
#define IPV4_RFC1918_B "172.16.0.0/12"
#define IPV4_RFC1918_C "192.168.0.0/16"
#define IPV4_LIMITED_BROADCAST "255.255.255.255/32"
#define IPV6_MULTICAST "ff00::/8"
#define IPV6_LINKLOCAL "fe80::/64"
#define IPV6_LOOPBACK  "::1/128"

#define NO_LOOPBACK      0
#define LOOPBACK_ALLOWED 1

int duplicate_double_colons(char* address_str);
int is_ipv4_cidr(char* address_str);
int is_ipv4_single(char* address_str);
int is_ipv6_cidr(char* address_str);
int is_ipv6_single(char* address_str);
int is_any_cidr(char* address_str);
int is_any_single(char* address_str);
int is_valid_address(CIDR *address);
int is_ipv4(CIDR *address);
int is_ipv4_host(CIDR *address);
int is_ipv4_net(CIDR *address);
int is_ipv4_broadcast(CIDR *address);
int is_ipv4_multicast(CIDR *address);
int is_ipv4_loopback(CIDR *address);
int is_ipv4_link_local(CIDR *address);
int is_ipv4_rfc1918(CIDR *address);
int is_ipv6(CIDR *address);
int is_ipv6_host(CIDR *address);
int is_ipv6_net(CIDR *address);
int is_ipv6_multicast(CIDR *address);
int is_ipv6_link_local(CIDR *address);
int is_valid_intf_address(CIDR *address, char* address_str, int allow_loopback);
int is_any_host(CIDR *address);
int is_any_net(CIDR *address);

#endif /* IPADDRCHECK_FUNCTIONS_H */