Skip to content

Commit aa8a9b0

Browse files
committed
Merge branch 'master' into feature/4-configuration-of-source-ip-address
Conflicts: bird-rtrlib-cli.c cli.c rtr.c rtr.h
2 parents 3934dc3 + aa95416 commit aa8a9b0

File tree

5 files changed

+34
-83
lines changed

5 files changed

+34
-83
lines changed

bird-rtrlib-cli.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void init_bird_command(void) {
131131
* @param added
132132
*/
133133
void rtr_callback(
134-
struct pfx_table *table, const pfx_record record, const bool added
134+
struct pfx_table *table, const struct pfx_record record, const bool added
135135
) {
136136
// IP address buffer.
137137
static char ip_addr_str[INET6_ADDRSTRLEN];
@@ -230,8 +230,7 @@ int main(int argc, char *argv[]) {
230230
rtr_config = rtr_ssh_connect(
231231
config.rtr_host, config.rtr_port, config.rtr_bind_addr,
232232
config.rtr_ssh_hostkey_file, config.rtr_ssh_username,
233-
config.rtr_ssh_privkey_file, config.rtr_ssh_pubkey_file,
234-
&rtr_callback
233+
config.rtr_ssh_privkey_file, &rtr_callback
235234
);
236235
break;
237236
}

cli.c

+1-15
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
#define ARGKEY_RTRSSH_ENABLE 's'
3333
#define ARGKEY_RTRSSH_HOSTKEY 0x101
3434
#define ARGKEY_RTRSSH_PRIVKEY 0x102
35-
#define ARGKEY_RTRSSH_PUBKEY 0x103
36-
#define ARGKEY_RTRSSH_USERNAME 0x104
35+
#define ARGKEY_RTRSSH_USERNAME 0x103
3736

3837
// Parser function for argp_parse().
3938
static error_t argp_parser(int key, char *arg, struct argp_state *state) {
@@ -65,9 +64,6 @@ static error_t argp_parser(int key, char *arg, struct argp_state *state) {
6564
case ARGKEY_RTRSSH_PRIVKEY:
6665
config->rtr_ssh_privkey_file = arg;
6766
break;
68-
case ARGKEY_RTRSSH_PUBKEY:
69-
config->rtr_ssh_pubkey_file = arg;
70-
break;
7167
case ARGKEY_RTRSSH_USERNAME:
7268
config->rtr_ssh_username = arg;
7369
break;
@@ -152,16 +148,6 @@ int parse_cli(int argc, char **argv, struct config *config) {
152148
"used. Uses the user's default identity file if not specified.",
153149
2
154150
},
155-
{
156-
"rtr-ssh-pubkey",
157-
ARGKEY_RTRSSH_PUBKEY,
158-
"<RTR_SSH_PUBKEY_FILE>",
159-
0,
160-
"(optional) Path to a file containing the public key of the user "
161-
"to be authenticated with the RTR server if an SSH connection is "
162-
"used. Uses the user's default public key file if not specified.",
163-
2
164-
},
165151
{0}
166152
};
167153

config.h

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ struct config {
4444
char *rtr_ssh_username;
4545
char *rtr_ssh_hostkey_file;
4646
char *rtr_ssh_privkey_file;
47-
char *rtr_ssh_pubkey_file;
4847
};
4948

5049
/**

rtr.c

+30-60
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,22 @@
2929
// for later cleanup.
3030
static struct tr_tcp_config *tcp_config = 0;
3131

32-
/**
33-
* Creates and returns an `rtr_mgr_config` structure from the specified
34-
* `rtr_mgr_group` structure.
35-
* @param groups
36-
* @return
37-
*/
38-
static struct rtr_mgr_config *rtr_create_mgr_config(
39-
rtr_mgr_group *groups, unsigned int count
40-
) {
41-
// Initialize result.
42-
struct rtr_mgr_config *result = malloc(sizeof (struct rtr_mgr_config));
43-
memset(result, 0, sizeof (struct rtr_mgr_config));
44-
45-
// Populate result.
46-
result->groups = groups;
47-
result->len = count;
48-
49-
// Return result.
50-
return result;
51-
}
52-
5332
/**
5433
* Creates and returns a `rtr_mgr_group` structure from the specified
5534
* `rtr_socket` structure array containing the specified number of elements.
5635
* @param rtr_socket
5736
* @param count
5837
* @return
5938
*/
60-
static rtr_mgr_group *rtr_create_mgr_group(
39+
static struct rtr_mgr_group *rtr_create_mgr_group(
6140
struct rtr_socket *sockets, unsigned int count
6241
) {
63-
// Create a prototype rtr_mgr_group to be able to retrieve its size.
64-
// TODO: Remove when rtr_mgr_group is not an anonymous struct anymore.
65-
rtr_mgr_group prototype;
66-
6742
// Iterator.
6843
unsigned int i;
6944

7045
// Initialize result.
71-
rtr_mgr_group *result = malloc(sizeof prototype); // TODO: see above
72-
memset(result, 0, sizeof prototype); // TODO: see above.
46+
struct rtr_mgr_group *result = malloc(sizeof (struct rtr_mgr_group));
47+
memset(result, 0, sizeof (struct rtr_mgr_group));
7348

7449
// Populate result.
7550
result->sockets = malloc(count * sizeof (struct rtr_socket *));
@@ -109,7 +84,6 @@ static struct rtr_socket *rtr_create_rtr_socket(struct tr_socket *socket) {
10984
* @param server_hostkey_path
11085
* @param username
11186
* @param client_privkey_path
112-
* @param client_pubkey_path
11387
* @return
11488
*/
11589
static struct tr_ssh_config *rtr_create_ssh_config(
@@ -118,8 +92,7 @@ static struct tr_ssh_config *rtr_create_ssh_config(
11892
const char *bindaddr,
11993
const char *server_hostkey_path,
12094
const char *username,
121-
const char *client_privkey_path,
122-
const char *client_pubkey_path
95+
const char *client_privkey_path
12396
) {
12497
// Initialize result.
12598
struct tr_ssh_config *result = malloc(sizeof (struct tr_ssh_config));
@@ -139,8 +112,6 @@ static struct tr_ssh_config *rtr_create_ssh_config(
139112
result->server_hostkey_path = strdup(server_hostkey_path);
140113
if (client_privkey_path)
141114
result->client_privkey_path = strdup(client_privkey_path);
142-
if (client_pubkey_path)
143-
result->client_pubkey_path = strdup(client_pubkey_path);
144115

145116
// Return result.
146117
return result;
@@ -256,29 +227,29 @@ void rtr_close(struct rtr_mgr_config *rtr_mgr_config) {
256227
struct rtr_mgr_config *rtr_ssh_connect(
257228
const char *host, const char *port, const char *bindaddr,
258229
const char *hostkey_file, const char *username, const char *privkey_file,
259-
const char *pubkey_file, const pfx_update_fp callback
230+
const pfx_update_fp callback
260231
) {
261-
// Create RTR manager config with the single server group.
262-
struct rtr_mgr_config *result = rtr_create_mgr_config(
263-
rtr_create_mgr_group(
264-
rtr_create_rtr_socket(
265-
rtr_create_ssh_socket(rtr_create_ssh_config(
266-
host,
267-
strtoul(port, 0, 10),
268-
bindaddr,
269-
hostkey_file,
270-
username,
271-
privkey_file,
272-
pubkey_file
273-
))
274-
),
275-
1
232+
// Prepare pointer to result config.
233+
struct rtr_mgr_config *result;
234+
235+
// Create the single server group.
236+
struct rtr_mgr_group *group = rtr_create_mgr_group(
237+
rtr_create_rtr_socket(
238+
rtr_create_ssh_socket(rtr_create_ssh_config(
239+
host,
240+
strtoul(port, 0, 10),
241+
bindaddr,
242+
hostkey_file,
243+
username,
244+
privkey_file
245+
))
276246
),
277247
1
278248
);
279249

280250
// Initialize RTR manager and bail out on error.
281-
if (rtr_mgr_init(result, 240, 520, callback) == RTR_ERROR) {
251+
result = rtr_mgr_init(group, 1, 240, 520, callback, 0, 0);
252+
if (!result) {
282253
fprintf(stderr, "Error initializing RTR manager.");
283254
return 0;
284255
}
@@ -297,21 +268,20 @@ struct rtr_mgr_config *rtr_tcp_connect(
297268
const char *host, const char *port, const char *bindaddr,
298269
const pfx_update_fp callback
299270
) {
300-
// Create RTR manager config with the single server group.
301-
struct rtr_mgr_config *result = rtr_create_mgr_config(
302-
rtr_create_mgr_group(
303-
rtr_create_rtr_socket(
304-
rtr_create_tcp_socket(
305-
rtr_create_tcp_config(host, port, bindaddr)
306-
)
307-
),
308-
1
271+
// Prepare pointer to result config.
272+
struct rtr_mgr_config *result;
273+
274+
// Create the single server group.
275+
struct rtr_mgr_group *group = rtr_create_mgr_group(
276+
rtr_create_rtr_socket(
277+
rtr_create_tcp_socket(rtr_create_tcp_config(host, port, bindaddr))
309278
),
310279
1
311280
);
312281

313282
// Initialize RTR manager and bail out on error.
314-
if (rtr_mgr_init(result, 240, 520, callback) == RTR_ERROR) {
283+
result = rtr_mgr_init(group, 1, 240, 520, callback, 0, 0);
284+
if (!result) {
315285
fprintf(stderr, "Error initializing RTR manager.");
316286
return 0;
317287
}

rtr.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,12 @@
3838
* @param privkey_file path to a file containing the private key to be used for
3939
* authentication with the SSH server. If set to a null pointer, the user's
4040
* default identity is used.
41-
* @param pubkey_file path to a file containing the public key to be used for
42-
* authentication with the SSH server. If set to a null pointer, the user's
43-
* default public key is used.
4441
* @param callback callback function for RTR updates.
4542
* @return
4643
*/
4744
struct rtr_mgr_config *rtr_ssh_connect(
4845
const char *, const char *, const char *, const char *, const char *,
49-
const char *, const char *, const pfx_update_fp
46+
const char *, const pfx_update_fp
5047
);
5148

5249
/**

0 commit comments

Comments
 (0)