Skip to content

Commit 3934dc3

Browse files
committed
Functioning source IP address support. Blocked by rtrlib/rtrlib#20. #4
1 parent 8cd3fe0 commit 3934dc3

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

bird-rtrlib-cli.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,16 @@ int main(int argc, char *argv[]) {
222222
switch (config.rtr_connection_type) {
223223
case tcp:
224224
rtr_config = rtr_tcp_connect(
225-
config.rtr_host, config.rtr_port, &rtr_callback
225+
config.rtr_host, config.rtr_port, config.rtr_bind_addr,
226+
&rtr_callback
226227
);
227228
break;
228229
case ssh:
229230
rtr_config = rtr_ssh_connect(
230-
config.rtr_host, config.rtr_port, config.rtr_ssh_hostkey_file,
231-
config.rtr_ssh_username, config.rtr_ssh_privkey_file,
232-
config.rtr_ssh_pubkey_file, &rtr_callback
231+
config.rtr_host, config.rtr_port, config.rtr_bind_addr,
232+
config.rtr_ssh_hostkey_file, config.rtr_ssh_username,
233+
config.rtr_ssh_privkey_file, config.rtr_ssh_pubkey_file,
234+
&rtr_callback
233235
);
234236
break;
235237
}

rtr.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ static struct rtr_socket *rtr_create_rtr_socket(struct tr_socket *socket) {
115115
static struct tr_ssh_config *rtr_create_ssh_config(
116116
const char *host,
117117
const unsigned int port,
118+
const char *bindaddr,
118119
const char *server_hostkey_path,
119120
const char *username,
120121
const char *client_privkey_path,
@@ -129,6 +130,10 @@ static struct tr_ssh_config *rtr_create_ssh_config(
129130
result->port = port;
130131
result->username = strdup(username);
131132

133+
// Assign bind address if available.
134+
if (bindaddr)
135+
result->bindaddr = strdup(bindaddr);
136+
132137
// Assign key paths (optional).
133138
if (server_hostkey_path)
134139
result->server_hostkey_path = strdup(server_hostkey_path);
@@ -173,7 +178,7 @@ static struct tr_socket *rtr_create_ssh_socket(
173178
* @return
174179
*/
175180
static struct tr_tcp_config *rtr_create_tcp_config(
176-
const char *host, const char *port
181+
const char *host, const char *port, const char *bindaddr
177182
) {
178183
// Initialize result.
179184
struct tr_tcp_config *result = malloc(sizeof (struct tr_tcp_config));
@@ -182,6 +187,7 @@ static struct tr_tcp_config *rtr_create_tcp_config(
182187
// Populate result.
183188
result->host = strdup(host);
184189
result->port = strdup(port);
190+
result->bindaddr = strdup(bindaddr);
185191

186192
// Store result in static variable until RTRLIB copies and frees the config.
187193
tcp_config = result;
@@ -248,9 +254,9 @@ void rtr_close(struct rtr_mgr_config *rtr_mgr_config) {
248254
}
249255

250256
struct rtr_mgr_config *rtr_ssh_connect(
251-
const char *host, const char *port, const char *hostkey_file,
252-
const char *username, const char *privkey_file, const char *pubkey_file,
253-
const pfx_update_fp callback
257+
const char *host, const char *port, const char *bindaddr,
258+
const char *hostkey_file, const char *username, const char *privkey_file,
259+
const char *pubkey_file, const pfx_update_fp callback
254260
) {
255261
// Create RTR manager config with the single server group.
256262
struct rtr_mgr_config *result = rtr_create_mgr_config(
@@ -259,6 +265,7 @@ struct rtr_mgr_config *rtr_ssh_connect(
259265
rtr_create_ssh_socket(rtr_create_ssh_config(
260266
host,
261267
strtoul(port, 0, 10),
268+
bindaddr,
262269
hostkey_file,
263270
username,
264271
privkey_file,
@@ -287,13 +294,16 @@ struct rtr_mgr_config *rtr_ssh_connect(
287294
}
288295

289296
struct rtr_mgr_config *rtr_tcp_connect(
290-
const char *host, const char *port, const pfx_update_fp callback
297+
const char *host, const char *port, const char *bindaddr,
298+
const pfx_update_fp callback
291299
) {
292300
// Create RTR manager config with the single server group.
293301
struct rtr_mgr_config *result = rtr_create_mgr_config(
294302
rtr_create_mgr_group(
295303
rtr_create_rtr_socket(
296-
rtr_create_tcp_socket(rtr_create_tcp_config(host, port))
304+
rtr_create_tcp_socket(
305+
rtr_create_tcp_config(host, port, bindaddr)
306+
)
297307
),
298308
1
299309
),

rtr.h

+11-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
* Returns a null pointer on error.
3131
* @param host host name of the SSH server.
3232
* @param port port number of the SSH server in string representation.
33+
* @param bindaddr host name or IP address the RTR connection shall be made from
34+
* (null pointer for any).
3335
* @param hostkey_file path to a file containing the host key of the specified
3436
* server. If set to a null pointer, the default known_hosts file is used.
3537
* @param username name of the user to be authenticated with the SSH server.
@@ -39,25 +41,26 @@
3941
* @param pubkey_file path to a file containing the public key to be used for
4042
* authentication with the SSH server. If set to a null pointer, the user's
4143
* default public key is used.
42-
* @param callback
44+
* @param callback callback function for RTR updates.
4345
* @return
4446
*/
4547
struct rtr_mgr_config *rtr_ssh_connect(
4648
const char *, const char *, const char *, const char *, const char *,
47-
const char *, const pfx_update_fp
49+
const char *, const char *, const pfx_update_fp
4850
);
4951

5052
/**
51-
* Connects to the RTR server at the specified address and port with plain TCP
52-
* using the specified callback function for RTR updates and returns the
53+
* Connects to the RTR server with the specified parameters and returns the
5354
* corresponding `rtr_mgr_config` structure. Returns a null pointer on error.
54-
* @param host
55-
* @param port
56-
* @param callback
55+
* @param host host name of the TCP server.
56+
* @param port port number of the TCP server in string representation.
57+
* @param bindaddr host name or IP address the RTR connection shall be made from
58+
* (null pointer for any).
59+
* @param callback callback function for RTR updates.
5760
* @return
5861
*/
5962
struct rtr_mgr_config *rtr_tcp_connect(
60-
const char *, const char *, const pfx_update_fp
63+
const char *, const char *, const char *, const pfx_update_fp
6164
);
6265

6366
/**

0 commit comments

Comments
 (0)