Author: tjansen Date: Wed Oct 28 14:47:28 2009 New Revision: 1381 Log: Renamed file descriptors. All filedescriptors managed in ctx are now prefixed with fd_. The names tunc, tund and tunnel were easy to confuse: tunc -> fd_control (UDP control socket, {,de}registering, heartbeat etc.) tund -> fd_data (UDP data socket, forwards encapsulated IP packets) tunnel -> fd_tunnel (pisaTunnel0 device) Modified: trunk/pisacd/cdctx.c trunk/pisacd/cdctx.h trunk/pisacd/cdderegister.c trunk/pisacd/cdheartbeat.c trunk/pisacd/cdmain.c trunk/pisacd/cdregister.c trunk/pisacd/cdtun.c trunk/pisasd/sdctx.c trunk/pisasd/sdctx.h trunk/pisasd/sdderegister.c trunk/pisasd/sdheartbeat.c trunk/pisasd/sdmain.c trunk/pisasd/sdregister.c trunk/pisasd/sdtun.c Modified: trunk/pisacd/cdctx.c ============================================================================== --- trunk/pisacd/cdctx.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisacd/cdctx.c Wed Oct 28 14:47:28 2009 (r1381) @@ -31,9 +31,11 @@ cdctx->is_cd_running = FALSE; cdctx->is_bgrun = FALSE; cdctx->pending = 0; - cdctx->tunnel = -1; - cdctx->tunc = -1; - cdctx->tund = -1; + + cdctx->fd_tunnel = -1; + cdctx->fd_control = -1; + cdctx->fd_data = -1; + cdctx->fd_pisaconf = -1; cdctx->ctrlhandlers = NULL; cdctx->natlist = NULL; Modified: trunk/pisacd/cdctx.h ============================================================================== --- trunk/pisacd/cdctx.h Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisacd/cdctx.h Wed Oct 28 14:47:28 2009 (r1381) @@ -44,11 +44,11 @@ int pending; /** - * Sockets for the tunnel device, the tunc and tund sockets + * Sockets for the data port, control port and the tunnel device. */ - int tund; - int tunc; - int tunnel; + int fd_data; + int fd_control; + int fd_tunnel; pisa_conmgr_entry *defaultroute; /** Modified: trunk/pisacd/cdderegister.c ============================================================================== --- trunk/pisacd/cdderegister.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisacd/cdderegister.c Wed Oct 28 14:47:28 2009 (r1381) @@ -70,7 +70,7 @@ inet_ntop(AF_INET6, &pend->key.addr.sin6_addr, buffer, sizeof(buffer)); PISA_DEBUG(PL_DEREGISTER, "Sending DEREGISTER to %s, try %i\n", buffer, pend->count); pisa_conmgr_build_sockaddr_control(pend->entry, &addr); - pisa_send_control_packet_ipv6_type(cd_ctx.tunc, &addr, PISA_PKTTYPE_TUN_DEREGISTER); + pisa_send_control_packet_ipv6_type(cd_ctx.fd_control, &addr, PISA_PKTTYPE_TUN_DEREGISTER); return PISA_PENDING_RESCHEDULE; } } Modified: trunk/pisacd/cdheartbeat.c ============================================================================== --- trunk/pisacd/cdheartbeat.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisacd/cdheartbeat.c Wed Oct 28 14:47:28 2009 (r1381) @@ -58,7 +58,7 @@ if (pend->entry->status == PISA_CON_CONNECTED) { PISA_DEBUG(PL_HEARTBEAT, "Sending HEARTBEAT to %s, try %i\n", buffer, pend->count); pisa_conmgr_build_sockaddr_control(pend->entry, &addr); - pisa_send_control_packet_ipv6_type(cd_ctx.tunc, &addr, PISA_PKTTYPE_TUN_HEARTBEAT); + pisa_send_control_packet_ipv6_type(cd_ctx.fd_control, &addr, PISA_PKTTYPE_TUN_HEARTBEAT); return PISA_PENDING_RESCHEDULE; } else { PISA_DEBUG(PL_HEARTBEAT, "Skipping HEARTBEAT to %s, wrong status\n", buffer); Modified: trunk/pisacd/cdmain.c ============================================================================== --- trunk/pisacd/cdmain.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisacd/cdmain.c Wed Oct 28 14:47:28 2009 (r1381) @@ -98,24 +98,24 @@ PISA_INFO("\nEntering main loop\n"); - maxfd = pisa_maxof(5, cd_ctx.tunnel, cd_ctx.fd_pisaconf, - cd_ctx.tunc, cd_ctx.tund, cd_ctx.scheduler.pipe_main[0]) + 1; + maxfd = pisa_maxof(5, cd_ctx.fd_tunnel, cd_ctx.fd_pisaconf, + cd_ctx.fd_control, cd_ctx.fd_data, cd_ctx.scheduler.pipe_main[0]) + 1; while (cd_ctx.is_cd_running || cd_ctx.pending) { /* sockets.tunnel needs to be always included in the reading fd list */ FD_ZERO(&readfds); - FD_SET(cd_ctx.tunnel, &readfds); - FD_SET(cd_ctx.tunc, &readfds); - FD_SET(cd_ctx.tund, &readfds); + FD_SET(cd_ctx.fd_tunnel, &readfds); + FD_SET(cd_ctx.fd_control, &readfds); + FD_SET(cd_ctx.fd_data, &readfds); FD_SET(cd_ctx.fd_pisaconf, &readfds); FD_SET(cd_ctx.scheduler.pipe_main[0], &readfds); if (select(maxfd, &readfds, NULL, NULL, NULL) > 0) { if (cd_ctx.is_cd_running) { - if (FD_ISSET(cd_ctx.tunnel, &readfds)) + if (FD_ISSET(cd_ctx.fd_tunnel, &readfds)) pisa_cd_copy_from_tun_to_sock(); - if (FD_ISSET(cd_ctx.tund, &readfds)) + if (FD_ISSET(cd_ctx.fd_data, &readfds)) pisa_cd_copy_from_sock_to_tun(); } else { /* TODO: Incoming packets after @@ -125,8 +125,8 @@ * above. */ } - if (FD_ISSET(cd_ctx.tunc, &readfds)) - pisa_ctrlhandler_dispatch(&cd_ctx.ctrlhandlers, cd_ctx.tunc); + if (FD_ISSET(cd_ctx.fd_control, &readfds)) + pisa_ctrlhandler_dispatch(&cd_ctx.ctrlhandlers, cd_ctx.fd_control); if (FD_ISSET(cd_ctx.fd_pisaconf, &readfds)) pisa_conf_handle_packet(cd_ctx.fd_pisaconf); @@ -396,13 +396,13 @@ cdconf_set_debuglevel(&cd_cfg); /* Make default sockets */ - cd_ctx.tunnel = pisa_tunnel_open_tundev(cd_ctx.ifname_tunnel, IFNAMSIZ); + cd_ctx.fd_tunnel = pisa_tunnel_open_tundev(cd_ctx.ifname_tunnel, IFNAMSIZ); cd_ctx.fd_pisaconf = pisa_conf_open_server_socket(PISA_CONF_PORT_CD); /* open peer sockets targeting the pisa server daemon, * through the tunnel, using HIT as the target IPv6 address. */ - cd_ctx.tunc = pisa_tunnel_open_socket(cd_cfg.port_control); - cd_ctx.tund = pisa_tunnel_open_socket(cd_cfg.port_data); + cd_ctx.fd_control = pisa_tunnel_open_socket(cd_cfg.port_control); + cd_ctx.fd_data = pisa_tunnel_open_socket(cd_cfg.port_data); /* set handlers for tunnel control packet types */ pisa_ctrlhandler_set(&cd_ctx.ctrlhandlers, PISA_PKTTYPE_TUN_REGISTER_ACK, pisa_recv_register_ack); @@ -443,9 +443,9 @@ pisa_sched_cleanup(&cd_ctx.scheduler); close(cd_ctx.fd_pisaconf); - close(cd_ctx.tunc); - close(cd_ctx.tund); - close(cd_ctx.tunnel); + close(cd_ctx.fd_control); + close(cd_ctx.fd_data); + close(cd_ctx.fd_tunnel); pisa_ctrlhandler_cleanup(&cd_ctx.ctrlhandlers); Modified: trunk/pisacd/cdregister.c ============================================================================== --- trunk/pisacd/cdregister.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisacd/cdregister.c Wed Oct 28 14:47:28 2009 (r1381) @@ -48,7 +48,7 @@ pisa_set_packet_type(packet, PISA_PKTTYPE_TUN_REGISTER); pisa_set_packet_length(packet, sizeof(pisa_packet_common) + sizeof(pisa_payload_register)); - pisa_send_control_packet_ipv6(cd_ctx.tunc, &pend->key.addr, packet); + pisa_send_control_packet_ipv6(cd_ctx.fd_control, &pend->key.addr, packet); pisa_free_msg(packet); return PISA_PENDING_RESCHEDULE; } Modified: trunk/pisacd/cdtun.c ============================================================================== --- trunk/pisacd/cdtun.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisacd/cdtun.c Wed Oct 28 14:47:28 2009 (r1381) @@ -41,7 +41,7 @@ addrlen = sizeof (from); - if ((len = recvfrom (cd_ctx.tund, buffer, sizeof(buffer), 0, (struct sockaddr *) &from, &addrlen)) == -1) { + if ((len = recvfrom (cd_ctx.fd_data, buffer, sizeof(buffer), 0, (struct sockaddr *) &from, &addrlen)) == -1) { PISA_ERROR("remote -> local: recvfrom failed: %s\n", strerror(errno)); return; } @@ -70,7 +70,7 @@ pisa_nat_apply(hdr, srcaddr, &map->local_private); /* Send the packet out to the tunnel device */ - if (write(cd_ctx.tunnel, buffer + 6, len - 6) == -1) { + if (write(cd_ctx.fd_tunnel, buffer + 6, len - 6) == -1) { PISA_ERROR("remote -> local: write failed: %s\n", strerror(errno)); } else { /* Sending a heartbeat at the next scheduled time is @@ -106,7 +106,7 @@ pisa_mac *mac = (pisa_mac *)buffer; struct sockaddr_in6 addr; - if ((len = read(cd_ctx.tunnel, buffer + 6, sizeof(buffer) - 6)) < 0) { + if ((len = read(cd_ctx.fd_tunnel, buffer + 6, sizeof(buffer) - 6)) < 0) { PISA_ERROR("local -> remote: read failed: %s\n", strerror(errno)); return; } @@ -158,7 +158,7 @@ * on the server side this connection is associated with the * control socket address and port number! */ pisa_conmgr_build_sockaddr_data(entry, &addr); - if (sendto(cd_ctx.tund, buffer, len + 6, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in6)) == -1) { + if (sendto(cd_ctx.fd_data, buffer, len + 6, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in6)) == -1) { PISA_ERROR("local -> remote: sendto failed: %s\n", strerror(errno)); } else { /* Keep track of the last time this connection was Modified: trunk/pisasd/sdctx.c ============================================================================== --- trunk/pisasd/sdctx.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisasd/sdctx.c Wed Oct 28 14:47:28 2009 (r1381) @@ -30,9 +30,10 @@ { sdctx->is_sd_running = FALSE; sdctx->is_bgrun = FALSE; - sdctx->tunc = -1; - sdctx->tund = -1; - sdctx->tunnel= -1; + + sdctx->fd_control = -1; + sdctx->fd_data = -1; + sdctx->fd_tunnel= -1; sdctx->fd_pisaconf = -1; sdctx->tunnel_device_name[0] = 0; Modified: trunk/pisasd/sdctx.h ============================================================================== --- trunk/pisasd/sdctx.h Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisasd/sdctx.h Wed Oct 28 14:47:28 2009 (r1381) @@ -37,11 +37,11 @@ int is_bgrun; /** - * Sockets for the tunnel device, the tunc and tund sockets + * Sockets for the data port, control port and the tunnel device. */ - int tund; - int tunc; - int tunnel; + int fd_data; + int fd_control; + int fd_tunnel; /** * Socket for pisaconf Modified: trunk/pisasd/sdderegister.c ============================================================================== --- trunk/pisasd/sdderegister.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisasd/sdderegister.c Wed Oct 28 14:47:28 2009 (r1381) @@ -34,5 +34,5 @@ } else { PISA_DEBUG(PL_STATEMACHINE|PL_DEREGISTER, "Deregister from unconnected client %s\n", buffer); } - pisa_send_control_packet_ipv6_type(sd_ctx.tunc, addr, PISA_PKTTYPE_TUN_DEREGISTER_ACK); + pisa_send_control_packet_ipv6_type(sd_ctx.fd_control, addr, PISA_PKTTYPE_TUN_DEREGISTER_ACK); } Modified: trunk/pisasd/sdheartbeat.c ============================================================================== --- trunk/pisasd/sdheartbeat.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisasd/sdheartbeat.c Wed Oct 28 14:47:28 2009 (r1381) @@ -56,7 +56,7 @@ if (e) { e->heartbeat_flag = 1; - pisa_send_control_packet_ipv6_type(sd_ctx.tunc, addr, PISA_PKTTYPE_TUN_HEARTBEAT_ACK); + pisa_send_control_packet_ipv6_type(sd_ctx.fd_control, addr, PISA_PKTTYPE_TUN_HEARTBEAT_ACK); inet_ntop(AF_INET6, &addr->sin6_addr, buffer, sizeof(buffer)); PISA_INFO("Heartbeat from client %s\n", buffer); } Modified: trunk/pisasd/sdmain.c ============================================================================== --- trunk/pisasd/sdmain.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisasd/sdmain.c Wed Oct 28 14:47:28 2009 (r1381) @@ -105,8 +105,8 @@ { int maxfd; - maxfd = 1 + pisa_maxof(5, sd_ctx.tunc, sd_ctx.tund, sd_ctx.tunnel, - sd_ctx.tunnel, sd_ctx.scheduler.pipe_main[0]); + maxfd = 1 + pisa_maxof(5, sd_ctx.fd_control, sd_ctx.fd_data, sd_ctx.fd_tunnel, + sd_ctx.fd_tunnel, sd_ctx.scheduler.pipe_main[0]); sd_ctx.is_sd_running = TRUE; PISA_INFO("\nEntering main loop\n"); @@ -116,20 +116,20 @@ /* Add all sockets to the read set */ FD_ZERO(&readfds); - FD_SET(sd_ctx.tunc, &readfds); - FD_SET(sd_ctx.tund, &readfds); - FD_SET(sd_ctx.tunnel, &readfds); + FD_SET(sd_ctx.fd_control, &readfds); + FD_SET(sd_ctx.fd_data, &readfds); + FD_SET(sd_ctx.fd_tunnel, &readfds); FD_SET(sd_ctx.fd_pisaconf, &readfds); FD_SET(sd_ctx.scheduler.pipe_main[0], &readfds); if (select(maxfd, &readfds, NULL, NULL, NULL) > 0) { - if (FD_ISSET(sd_ctx.tunc, &readfds)) - pisa_ctrlhandler_dispatch(&sd_ctx.ctrlhandlers, sd_ctx.tunc); + if (FD_ISSET(sd_ctx.fd_control, &readfds)) + pisa_ctrlhandler_dispatch(&sd_ctx.ctrlhandlers, sd_ctx.fd_control); - if (FD_ISSET(sd_ctx.tund, &readfds)) + if (FD_ISSET(sd_ctx.fd_data, &readfds)) pisa_sd_copy_from_sock_to_tun(); - if (FD_ISSET(sd_ctx.tunnel, &readfds)) + if (FD_ISSET(sd_ctx.fd_tunnel, &readfds)) pisa_sd_copy_from_tun_to_sock(); if (FD_ISSET(sd_ctx.fd_pisaconf, &readfds)) @@ -412,8 +412,8 @@ sdconf_set_debuglevel(&sd_cfg); /* Make default sockets */ - sd_ctx.tunc = pisa_tunnel_open_socket(sd_cfg.port_control); - sd_ctx.tund = pisa_tunnel_open_socket(sd_cfg.port_data); + sd_ctx.fd_control = pisa_tunnel_open_socket(sd_cfg.port_control); + sd_ctx.fd_data = pisa_tunnel_open_socket(sd_cfg.port_data); sd_ctx.fd_pisaconf = pisa_conf_open_server_socket(PISA_CONF_PORT_SD); /* Enable NAT if this process is a relay server */ @@ -445,7 +445,7 @@ /* create the tunnel device and assign an IP address */ inet_pton(AF_INET, "255.255.255.0", &netmask); - sd_ctx.tunnel = pisa_tunnel_open_tundev(sd_ctx.tunnel_device_name, IFNAMSIZ); + sd_ctx.fd_tunnel = pisa_tunnel_open_tundev(sd_ctx.tunnel_device_name, IFNAMSIZ); pisa_tunnel_configure_main(sd_ctx.tunnel_device_name, &sd_cfg.ipaddr, &netmask, MTU_TUN); /* Initialize the scheduler */ @@ -475,9 +475,9 @@ /* Close file descriptors. pisa_sched_cleanup takes care of the * scheduler pipe. */ - close(sd_ctx.tunc); - close(sd_ctx.tund); - close(sd_ctx.tunnel); + close(sd_ctx.fd_control); + close(sd_ctx.fd_data); + close(sd_ctx.fd_tunnel); close(sd_ctx.fd_pisaconf); pisa_sched_cleanup(&sd_ctx.scheduler); Modified: trunk/pisasd/sdregister.c ============================================================================== --- trunk/pisasd/sdregister.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisasd/sdregister.c Wed Oct 28 14:47:28 2009 (r1381) @@ -34,7 +34,7 @@ pisa_set_packet_length(packet, sizeof(pisa_packet_common) + sizeof(pisa_payload_registerack)); pisa_conmgr_build_sockaddr_control(e, &addr); - pisa_send_control_packet_ipv6(sd_ctx.tunc, &addr, packet); + pisa_send_control_packet_ipv6(sd_ctx.fd_control, &addr, packet); pisa_free_msg(packet); } Modified: trunk/pisasd/sdtun.c ============================================================================== --- trunk/pisasd/sdtun.c Wed Oct 28 14:28:03 2009 (r1380) +++ trunk/pisasd/sdtun.c Wed Oct 28 14:47:28 2009 (r1381) @@ -54,7 +54,7 @@ addrlen = sizeof(from); - if ((len = recvfrom(sd_ctx.tund, buffer, sizeof(buffer), 0, (struct sockaddr *) &from, &addrlen)) == -1) { + if ((len = recvfrom(sd_ctx.fd_data, buffer, sizeof(buffer), 0, (struct sockaddr *) &from, &addrlen)) == -1) { PISA_ERROR("remote -> local: recvfrom failed: %s\n", strerror(errno)); return; } @@ -114,7 +114,7 @@ pisa_nat_apply(hdr, srcaddr, &map->local_private); /* Send the packet out to the tunnel device */ - if (write(sd_ctx.tunnel, buffer + 6, len - 6) == -1) + if (write(sd_ctx.fd_tunnel, buffer + 6, len - 6) == -1) PISA_ERROR("remote -> local: write failed: %s\n", strerror(errno)); else { @@ -147,7 +147,7 @@ /* Clean the 6 MAC bytes at the head of the buffer. */ memset(buffer, 0, 6); - if ((len = read(sd_ctx.tunnel, buffer + 6, sizeof(buffer) - 6)) < 0) { + if ((len = read(sd_ctx.fd_tunnel, buffer + 6, sizeof(buffer) - 6)) < 0) { PISA_ERROR("local -> remote: read failed: %s\n", strerror(errno)); return; } @@ -185,7 +185,7 @@ } else { /* Send the packet out to the data port of the connection entry */ pisa_conmgr_build_sockaddr_data(entry, &addr); - if (sendto(sd_ctx.tund, buffer, len + 6, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in6)) == -1) + if (sendto(sd_ctx.fd_data, buffer, len + 6, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in6)) == -1) PISA_ERROR("local -> remote: sendto failed: %s\n", strerror(errno)); else { PISA_DEBUG(PL_DATA, "local -> remote: %i bytes\n", len);