summaryrefslogtreecommitdiff
path: root/proto/wireguard/config.Y
blob: 6d3b1ef61701736b9e14c087ff307b0fe8d4f2cd (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 *	BIRD -- Wireguard Protocol Configuration
 *
 *	(c) 1999 Martin Mares <mj@ucw.cz>
 *
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

CF_HDR

#include "proto/wireguard/wireguard.h"

CF_DEFINES

#define WG_DEFAULT_TUNNEL_TYPE 51820

#define WG_CFG ((struct wg_config *) this_proto)

static struct peer_config *this_peer = NULL;

CF_DECLS

CF_KEYWORDS(WIREGUARD, TUNNEL_TYPE, PRIVATE_KEY, LISTEN_PORT, PUBLIC_KEY, ENDPOINT, ALLOWED_IP)

CF_GRAMMAR

proto: wireguard_proto '}' ;

wireguard_proto_start: proto_start WIREGUARD {
     this_proto = proto_config_new(&proto_wireguard, $1);
     init_list(&WG_CFG->peers);
     WG_CFG->tunnel_type = WG_DEFAULT_TUNNEL_TYPE;
  }
 ;

wireguard_proto:
   wireguard_proto_start proto_name '{'
 | wireguard_proto wg_proto_channel ';'
 | wireguard_proto proto_item ';'
 | wireguard_proto TUNNEL_TYPE tunnel_type ';'
 | wireguard_proto INTERFACE TEXT ';' { WG_CFG->ifname = $3; }
 | wireguard_proto PRIVATE_KEY private_key ';'
 | wireguard_proto LISTEN_PORT listen_port ';'
 | wireguard_proto wg_peer ';'
 ;

wg_peer: wg_peer_start wg_peer_opt_list wg_peer_end;

wg_peer_start: PEER { this_peer = peer_new(WG_CFG); }

wg_peer_end: {
  this_peer = NULL;
}
 ;

wg_peer_item:
   PUBLIC_KEY public_key
 | ENDPOINT endpoint
 | PORT port
 | ALLOWED_IP allowedip
 ;

wg_peer_opts:
  /* empty */
 | wg_peer_opts wg_peer_item ';'
 ;

wg_peer_opt_list:
  /* empty */
 | '{' wg_peer_opts '}'
 ;

tunnel_type: expr { WG_CFG->tunnel_type = $1; }

private_key: text { WG_CFG->private_key = $1; }

listen_port: expr { WG_CFG->listen_port = $1; }

public_key: text { this_peer->public_key = $1; }

endpoint: ipa { this_peer->endpoint = $1; }

port: expr { this_peer->remote_port = $1; }

allowedip:
   net_or_ipa { this_peer->allowedip = $1; }
 ;

wg_proto_channel: wg_channel_start channel_opt_list wg_channel_end;

wg_channel_start: net_type
{
  this_channel = channel_config_get(&channel_wg, net_label[$1], $1, this_proto);
}

wg_channel_end:
{
  this_channel = NULL;
}

CF_CODE

CF_END