summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2023-03-22 12:57:15 +0100
committerSander Vrijders <sander@ouroboros.rocks>2023-03-24 10:04:53 +0100
commit51650a6dfcc0abc330200caf1ea89fcb6b8dce8b (patch)
treec7500822868663da3284c5ce31d70fb5c76999d1 /src/ipcpd
parentb69cb56fdc0343b7c25cc895f9841ff29f01da26 (diff)
downloadouroboros-51650a6dfcc0abc330200caf1ea89fcb6b8dce8b.tar.gz
ouroboros-51650a6dfcc0abc330200caf1ea89fcb6b8dce8b.zip
ipcpd: Use consistent function naming
For instance ipcp_udp_* vs eth_ipcp_*. Now all functions are <type>_ipcp_*. Als cleans up some minor things. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/ipcpd')
-rw-r--r--src/ipcpd/eth/eth.c10
-rw-r--r--src/ipcpd/local/main.c47
-rw-r--r--src/ipcpd/udp/main.c83
3 files changed, 70 insertions, 70 deletions
diff --git a/src/ipcpd/eth/eth.c b/src/ipcpd/eth/eth.c
index 6d9d78ba..15082ee3 100644
--- a/src/ipcpd/eth/eth.c
+++ b/src/ipcpd/eth/eth.c
@@ -1829,9 +1829,6 @@ int main(int argc,
{
int i;
- if (ipcp_init(argc, argv, &eth_ops, THIS_TYPE) < 0)
- goto fail_init;
-
if (eth_data_init() < 0) {
#if defined(BUILD_ETH_DIX)
log_err("Failed to init eth-llc data.");
@@ -1841,6 +1838,9 @@ int main(int argc,
goto fail_data_init;
}
+ if (ipcp_init(argc, argv, &eth_ops, THIS_TYPE) < 0)
+ goto fail_init;
+
if (ipcp_start() < 0) {
log_err("Failed to start IPCP.");
goto fail_start;
@@ -1878,9 +1878,9 @@ int main(int argc,
exit(EXIT_SUCCESS);
fail_start:
- eth_data_fini();
- fail_data_init:
ipcp_fini();
fail_init:
+ eth_data_fini();
+ fail_data_init:
exit(EXIT_FAILURE);
}
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c
index f43d4713..2fae01fd 100644
--- a/src/ipcpd/local/main.c
+++ b/src/ipcpd/local/main.c
@@ -84,6 +84,7 @@ static int local_data_init(void)
if (pthread_rwlock_init(&local_data.lock, NULL) < 0)
goto fail_rwlock_init;
+
return 0;
fail_rwlock_init:
@@ -97,13 +98,13 @@ static int local_data_init(void)
}
static void local_data_fini(void){
+ pthread_rwlock_destroy(&local_data.lock);
shim_data_destroy(local_data.shim_data);
- fset_destroy(local_data.flows);
fqueue_destroy(local_data.fq);
- pthread_rwlock_destroy(&local_data.lock);
+ fset_destroy(local_data.flows);
}
-static void * ipcp_local_packet_loop(void * o)
+static void * local_ipcp_packet_loop(void * o)
{
(void) o;
@@ -139,7 +140,7 @@ static void * ipcp_local_packet_loop(void * o)
return (void *) 0;
}
-static int ipcp_local_bootstrap(const struct ipcp_config * conf)
+static int local_ipcp_bootstrap(const struct ipcp_config * conf)
{
assert(conf);
assert(conf->type == THIS_TYPE);
@@ -150,7 +151,7 @@ static int ipcp_local_bootstrap(const struct ipcp_config * conf)
ipcp_set_state(IPCP_OPERATIONAL);
if (pthread_create(&local_data.packet_loop, NULL,
- ipcp_local_packet_loop, NULL)) {
+ local_ipcp_packet_loop, NULL)) {
ipcp_set_state(IPCP_INIT);
return -1;
}
@@ -160,7 +161,7 @@ static int ipcp_local_bootstrap(const struct ipcp_config * conf)
return 0;
}
-static int ipcp_local_reg(const uint8_t * hash)
+static int local_ipcp_reg(const uint8_t * hash)
{
if (shim_data_reg_add_entry(local_data.shim_data, hash)) {
log_dbg("Failed to add " HASH_FMT " to local registry.",
@@ -173,7 +174,7 @@ static int ipcp_local_reg(const uint8_t * hash)
return 0;
}
-static int ipcp_local_unreg(const uint8_t * hash)
+static int local_ipcp_unreg(const uint8_t * hash)
{
shim_data_reg_del_entry(local_data.shim_data, hash);
@@ -182,7 +183,7 @@ static int ipcp_local_unreg(const uint8_t * hash)
return 0;
}
-static int ipcp_local_query(const uint8_t * hash)
+static int local_ipcp_query(const uint8_t * hash)
{
int ret;
@@ -191,7 +192,7 @@ static int ipcp_local_query(const uint8_t * hash)
return ret;
}
-static int ipcp_local_flow_alloc(int fd,
+static int local_ipcp_flow_alloc(int fd,
const uint8_t * dst,
qosspec_t qs,
const void * data,
@@ -251,7 +252,7 @@ static int ipcp_local_flow_alloc(int fd,
return 0;
}
-static int ipcp_local_flow_alloc_resp(int fd,
+static int local_ipcp_flow_alloc_resp(int fd,
int response,
const void * data,
size_t len)
@@ -310,7 +311,7 @@ static int ipcp_local_flow_alloc_resp(int fd,
return 0;
}
-static int ipcp_local_flow_dealloc(int fd)
+static int local_ipcp_flow_dealloc(int fd)
{
assert(!(fd < 0));
@@ -332,30 +333,30 @@ static int ipcp_local_flow_dealloc(int fd)
}
static struct ipcp_ops local_ops = {
- .ipcp_bootstrap = ipcp_local_bootstrap,
+ .ipcp_bootstrap = local_ipcp_bootstrap,
.ipcp_enroll = NULL,
.ipcp_connect = NULL,
.ipcp_disconnect = NULL,
- .ipcp_reg = ipcp_local_reg,
- .ipcp_unreg = ipcp_local_unreg,
- .ipcp_query = ipcp_local_query,
- .ipcp_flow_alloc = ipcp_local_flow_alloc,
+ .ipcp_reg = local_ipcp_reg,
+ .ipcp_unreg = local_ipcp_unreg,
+ .ipcp_query = local_ipcp_query,
+ .ipcp_flow_alloc = local_ipcp_flow_alloc,
.ipcp_flow_join = NULL,
- .ipcp_flow_alloc_resp = ipcp_local_flow_alloc_resp,
- .ipcp_flow_dealloc = ipcp_local_flow_dealloc
+ .ipcp_flow_alloc_resp = local_ipcp_flow_alloc_resp,
+ .ipcp_flow_dealloc = local_ipcp_flow_dealloc
};
int main(int argc,
char * argv[])
{
- if (ipcp_init(argc, argv, &local_ops, THIS_TYPE) < 0)
- goto fail_init;
-
if (local_data_init() < 0) {
log_err("Failed to init local data.");
goto fail_data_init;
}
+ if (ipcp_init(argc, argv, &local_ops, THIS_TYPE) < 0)
+ goto fail_init;
+
if (ipcp_start() < 0) {
log_err("Failed to start IPCP.");
goto fail_start;
@@ -377,9 +378,9 @@ int main(int argc,
exit(EXIT_SUCCESS);
fail_start:
- local_data_fini();
- fail_data_init:
ipcp_fini();
fail_init:
+ local_data_fini();
+ fail_data_init:
exit(EXIT_FAILURE);
}
diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c
index 43975df1..b2170e0b 100644
--- a/src/ipcpd/udp/main.c
+++ b/src/ipcpd/udp/main.c
@@ -199,7 +199,7 @@ static void udp_data_fini(void)
pthread_mutex_destroy(&udp_data.mgmt_lock);
}
-static int ipcp_udp_port_alloc(const struct sockaddr_in * r_saddr,
+static int udp_ipcp_port_alloc(const struct sockaddr_in * r_saddr,
uint32_t s_eid,
const uint8_t * dst,
qosspec_t qs,
@@ -248,7 +248,7 @@ static int ipcp_udp_port_alloc(const struct sockaddr_in * r_saddr,
return 0;
}
-static int ipcp_udp_port_alloc_resp(const struct sockaddr_in * r_saddr,
+static int udp_ipcp_port_alloc_resp(const struct sockaddr_in * r_saddr,
uint32_t s_eid,
uint32_t d_eid,
int8_t response,
@@ -282,7 +282,7 @@ static int ipcp_udp_port_alloc_resp(const struct sockaddr_in * r_saddr,
return 0;
}
-static int ipcp_udp_port_req(struct sockaddr_in * c_saddr,
+static int udp_ipcp_port_req(struct sockaddr_in * c_saddr,
int d_eid,
const uint8_t * dst,
qosspec_t qs,
@@ -336,7 +336,7 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr,
return 0;
}
-static int ipcp_udp_port_alloc_reply(const struct sockaddr_in * saddr,
+static int udp_ipcp_port_alloc_reply(const struct sockaddr_in * saddr,
uint32_t s_eid,
uint32_t d_eid,
int8_t response,
@@ -370,7 +370,7 @@ static int ipcp_udp_port_alloc_reply(const struct sockaddr_in * saddr,
return 0;
}
-static int ipcp_udp_mgmt_frame(const uint8_t * buf,
+static int udp_ipcp_mgmt_frame(const uint8_t * buf,
size_t len,
struct sockaddr_in c_saddr)
{
@@ -396,14 +396,14 @@ static int ipcp_udp_mgmt_frame(const uint8_t * buf,
qs.cypher_s = ntoh16(msg->cypher_s);
qs.timeout = ntoh32(msg->timeout);
- return ipcp_udp_port_req(&c_saddr, ntoh32(msg->s_eid),
+ return udp_ipcp_port_req(&c_saddr, ntoh32(msg->s_eid),
(uint8_t *) (msg + 1), qs,
buf + msg_len,
len - msg_len);
case FLOW_REPLY:
assert(len >= sizeof(*msg));
- return ipcp_udp_port_alloc_reply(&c_saddr,
+ return udp_ipcp_port_alloc_reply(&c_saddr,
ntoh32(msg->s_eid),
ntoh32(msg->d_eid),
msg->response,
@@ -415,7 +415,7 @@ static int ipcp_udp_mgmt_frame(const uint8_t * buf,
}
}
-static void * ipcp_udp_mgmt_handler(void * o)
+static void * udp_ipcp_mgmt_handler(void * o)
{
(void) o;
@@ -437,7 +437,7 @@ static void * ipcp_udp_mgmt_handler(void * o)
pthread_mutex_unlock(&udp_data.mgmt_lock);
- ipcp_udp_mgmt_frame(frame->buf, frame->len, frame->r_saddr);
+ udp_ipcp_mgmt_frame(frame->buf, frame->len, frame->r_saddr);
free(frame);
}
@@ -447,7 +447,7 @@ static void * ipcp_udp_mgmt_handler(void * o)
return (void *) 0;
}
-static void * ipcp_udp_packet_reader(void * o)
+static void * udp_ipcp_packet_reader(void * o)
{
uint8_t buf[IPCP_UDP_MAX_PACKET_SIZE];
uint8_t * data;
@@ -517,7 +517,7 @@ static void * ipcp_udp_packet_reader(void * o)
ipcp_sdb_release(sdb);
}
- return 0;
+ return (void *) 0;
}
static void cleanup_fqueue(void * fq)
@@ -530,7 +530,7 @@ static void cleanup_sdb(void * sdb)
ipcp_sdb_release((struct shm_du_buff *) sdb);
}
-static void * ipcp_udp_packet_writer(void * o)
+static void * udp_ipcp_packet_writer(void * o)
{
fqueue_t * fq;
@@ -608,11 +608,10 @@ static const char * inet4_ntop(const void * addr,
return inet_ntop(AF_INET, addr, buf, INET_ADDRSTRLEN);
}
-static int ipcp_udp_bootstrap(const struct ipcp_config * conf)
+static int udp_ipcp_bootstrap(const struct ipcp_config * conf)
{
char ipstr[INET_ADDRSTRLEN];
char dnsstr[INET_ADDRSTRLEN];
- char portstr[128]; /* port is max 64535 = 5 chars */
int i = 1;
assert(conf);
@@ -661,14 +660,14 @@ static int ipcp_udp_bootstrap(const struct ipcp_config * conf)
ipcp_set_state(IPCP_OPERATIONAL);
if (pthread_create(&udp_data.mgmt_handler, NULL,
- ipcp_udp_mgmt_handler, NULL)) {
+ udp_ipcp_mgmt_handler, NULL)) {
ipcp_set_state(IPCP_INIT);
goto fail_bind;
}
for (i = 0; i < IPCP_UDP_RD_THR; ++i) {
if (pthread_create(&udp_data.packet_reader[i], NULL,
- ipcp_udp_packet_reader, NULL)) {
+ udp_ipcp_packet_reader, NULL)) {
ipcp_set_state(IPCP_INIT);
goto fail_packet_reader;
}
@@ -676,14 +675,12 @@ static int ipcp_udp_bootstrap(const struct ipcp_config * conf)
for (i = 0; i < IPCP_UDP_WR_THR; ++i) {
if (pthread_create(&udp_data.packet_writer[i], NULL,
- ipcp_udp_packet_writer, NULL)) {
+ udp_ipcp_packet_writer, NULL)) {
ipcp_set_state(IPCP_INIT);
goto fail_packet_writer;
}
}
- sprintf(portstr, "%d", conf->udp.port);
-
log_dbg("Bootstrapped IPCP over UDP with pid %d.", getpid());
log_dbg("Bound to IP address %s.", ipstr);
log_dbg("Using port %u.", conf->udp.port);
@@ -833,7 +830,7 @@ static uint32_t ddns_resolve(char * name,
}
#endif
-static int ipcp_udp_reg(const uint8_t * hash)
+static int udp_ipcp_reg(const uint8_t * hash)
{
#ifdef HAVE_DDNS
char ipstr[INET_ADDRSTRLEN];
@@ -894,7 +891,7 @@ static int ipcp_udp_reg(const uint8_t * hash)
return 0;
}
-static int ipcp_udp_unreg(const uint8_t * hash)
+static int udp_ipcp_unreg(const uint8_t * hash)
{
#ifdef HAVE_DDNS
char dnsstr[INET_ADDRSTRLEN];
@@ -938,7 +935,7 @@ static int ipcp_udp_unreg(const uint8_t * hash)
return 0;
}
-static int ipcp_udp_query(const uint8_t * hash)
+static int udp_ipcp_query(const uint8_t * hash)
{
uint32_t ip_addr = 0;
char * hashstr;
@@ -994,7 +991,7 @@ static int ipcp_udp_query(const uint8_t * hash)
return 0;
}
-static int ipcp_udp_flow_alloc(int fd,
+static int udp_ipcp_flow_alloc(int fd,
const uint8_t * dst,
qosspec_t qs,
const void * data,
@@ -1028,7 +1025,7 @@ static int ipcp_udp_flow_alloc(int fd,
r_saddr.sin_addr.s_addr = ip_addr;
r_saddr.sin_port = udp_data.s_saddr.sin_port;
- if (ipcp_udp_port_alloc(&r_saddr, fd, dst, qs, data, len) < 0) {
+ if (udp_ipcp_port_alloc(&r_saddr, fd, dst, qs, data, len) < 0) {
log_err("Could not allocate port.");
return -1;
}
@@ -1047,7 +1044,7 @@ static int ipcp_udp_flow_alloc(int fd,
return 0;
}
-static int ipcp_udp_flow_alloc_resp(int fd,
+static int udp_ipcp_flow_alloc_resp(int fd,
int resp,
const void * data,
size_t len)
@@ -1088,7 +1085,7 @@ static int ipcp_udp_flow_alloc_resp(int fd,
pthread_rwlock_unlock(&udp_data.flows_lock);
- if (ipcp_udp_port_alloc_resp(&saddr, d_eid, fd, resp, data, len) < 0) {
+ if (udp_ipcp_port_alloc_resp(&saddr, d_eid, fd, resp, data, len) < 0) {
fset_del(udp_data.np1_flows, fd);
log_err("Failed to respond to flow request.");
return -1;
@@ -1102,7 +1099,7 @@ static int ipcp_udp_flow_alloc_resp(int fd,
return 0;
}
-static int ipcp_udp_flow_dealloc(int fd)
+static int udp_ipcp_flow_dealloc(int fd)
{
ipcp_flow_fini(fd);
@@ -1123,17 +1120,17 @@ static int ipcp_udp_flow_dealloc(int fd)
}
static struct ipcp_ops udp_ops = {
- .ipcp_bootstrap = ipcp_udp_bootstrap,
+ .ipcp_bootstrap = udp_ipcp_bootstrap,
.ipcp_enroll = NULL,
.ipcp_connect = NULL,
.ipcp_disconnect = NULL,
- .ipcp_reg = ipcp_udp_reg,
- .ipcp_unreg = ipcp_udp_unreg,
- .ipcp_query = ipcp_udp_query,
- .ipcp_flow_alloc = ipcp_udp_flow_alloc,
+ .ipcp_reg = udp_ipcp_reg,
+ .ipcp_unreg = udp_ipcp_unreg,
+ .ipcp_query = udp_ipcp_query,
+ .ipcp_flow_alloc = udp_ipcp_flow_alloc,
.ipcp_flow_join = NULL,
- .ipcp_flow_alloc_resp = ipcp_udp_flow_alloc_resp,
- .ipcp_flow_dealloc = ipcp_udp_flow_dealloc
+ .ipcp_flow_alloc_resp = udp_ipcp_flow_alloc_resp,
+ .ipcp_flow_dealloc = udp_ipcp_flow_dealloc
};
int main(int argc,
@@ -1141,14 +1138,15 @@ int main(int argc,
{
int i;
- if (ipcp_init(argc, argv, &udp_ops, THIS_TYPE) < 0)
- goto fail_init;
if (udp_data_init() < 0) {
log_err("Failed to init udp data.");
goto fail_data_init;
}
+ if (ipcp_init(argc, argv, &udp_ops, THIS_TYPE) < 0)
+ goto fail_init;
+
if (ipcp_start() < 0) {
log_err("Failed to start IPCP.");
goto fail_start;
@@ -1157,17 +1155,18 @@ int main(int argc,
ipcp_sigwait();
if (ipcp_get_state() == IPCP_SHUTDOWN) {
- for (i = 0; i < IPCP_UDP_RD_THR; ++i)
- pthread_cancel(udp_data.packet_reader[i]);
for (i = 0; i < IPCP_UDP_WR_THR; ++i)
pthread_cancel(udp_data.packet_writer[i]);
+ for (i = 0; i < IPCP_UDP_RD_THR; ++i)
+ pthread_cancel(udp_data.packet_reader[i]);
pthread_cancel(udp_data.mgmt_handler);
- for (i = 0; i < IPCP_UDP_RD_THR; ++i)
- pthread_join(udp_data.packet_reader[i], NULL);
for (i = 0; i < IPCP_UDP_WR_THR; ++i)
pthread_join(udp_data.packet_writer[i], NULL);
+ for (i = 0; i < IPCP_UDP_RD_THR; ++i)
+ pthread_join(udp_data.packet_reader[i], NULL);
pthread_join(udp_data.mgmt_handler, NULL);
+ close(udp_data.s_fd);
}
ipcp_stop();
@@ -1179,9 +1178,9 @@ int main(int argc,
exit(EXIT_SUCCESS);
fail_start:
- udp_data_fini();
- fail_data_init:
ipcp_fini();
fail_init:
+ udp_data_fini();
+ fail_data_init:
exit(EXIT_FAILURE);
}