[pisa-src] r840 - in trunk: client/pisacd include libpisa trust-point/pisasd

  • From: Thomas Jansen <mithi@xxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Fri, 21 Aug 2009 12:13:37 +0200

Author: Tjansen
Date: Fri Aug 21 12:13:36 2009
New Revision: 840

Log:
Added two commands for pisacdconf: server and service. Parsing and packet
sending works, but packets have no effect yet in the client. Sending a packet
now honors the packet length.

Modified:
   trunk/client/pisacd/cdmain.c
   trunk/client/pisacd/pisacdconf.c
   trunk/client/pisacd/pisacdconf.h
   trunk/client/pisacd/pisaconftool.c
   trunk/include/pisaconf.h
   trunk/libpisa/pisaconf.c
   trunk/trust-point/pisasd/pisasdconf.c

Modified: trunk/client/pisacd/cdmain.c
==============================================================================
--- trunk/client/pisacd/cdmain.c        Thu Aug 20 16:23:09 2009        (r839)
+++ trunk/client/pisacd/cdmain.c        Fri Aug 21 12:13:36 2009        (r840)
@@ -231,7 +231,9 @@
        /* set handlers for config requests */
        memset(&conf_handle_func_set, 0, sizeof(conf_handle_func_set));
        conf_handle_func_set.debuglevel = pisa_conf_cb_debuglevel;
-       conf_handle_func_set.debugmask = pisa_conf_cb_debugmask;
+       conf_handle_func_set.debugmask = pisa_conf_cb_debugmask;;
+       conf_handle_func_set.serveradd = pisa_cdconf_cb_server_add;
+       conf_handle_func_set.serviceadd = pisa_cdconf_cb_service_add;
 
 /* TODO: Read a config file, long term goal is to replace libconfig.
        pisa_conf_read_file("foo", pisa_cdconf_parse);

Modified: trunk/client/pisacd/pisacdconf.c
==============================================================================
--- trunk/client/pisacd/pisacdconf.c    Thu Aug 20 16:23:09 2009        (r839)
+++ trunk/client/pisacd/pisacdconf.c    Fri Aug 21 12:13:36 2009        (r840)
@@ -19,6 +19,118 @@
 
 #include "debug.h"
 #include "pisaconf.h"
+#include "packet.h"
+
+/**
+ * Parse a pisacdconf server line and send out a packet to the client daemon.
+ * @param argc number of arguments
+ * @param argv array of arguments
+ * @return 0 on success, 1 on general error, 2 on specific error.
+ */
+static int pisa_cdconf_parse_server(int argc, char *argv[])
+{
+       pisa_conf_packet *packet;
+       pisa_conf_serveradd *serveradd;
+
+       if (argc != 2) {
+               PISA_ERROR("'server' needs 2 arguments.\n");
+               return 2;
+       }
+
+       packet = pisa_conf_packet_new_request();
+       serveradd = &packet->body.request.rdata.serveradd;
+       packet->body.request.header.type = htons(PISA_CONF_REQUEST_SERVER_ADD);
+       pisa_conf_packet_add_len(packet, sizeof(pisa_conf_serveradd));
+
+       if (inet_pton(AF_INET6, argv[0], &serveradd->hit) != 1) {
+               PISA_ERROR("HIT could not be parsed.\n");
+               return 2;
+       }
+
+       if (!strcmp("relay", argv[1])) {
+               serveradd->type = PISA_CONTYPE_RELAY;
+       } else if (!strcmp("service", argv[1])) {
+               serveradd->type = PISA_CONTYPE_SERVICE;
+       } else if (!strcmp("legacyrouter", argv[1])) {
+               serveradd->type = PISA_CONTYPE_LEGACY_ROUTER;
+       } else {
+               PISA_ERROR("Type '%s' not valid. Choose from 'relay', 'service' 
or 'legacyrouter'.\n", argv[1]);
+               return 2;
+       }
+
+       pisa_conf_send_packet(packet);
+       free(packet);
+
+       return 0;
+}
+
+/**
+ * Handle a pisacdconf server add request.
+ * @param packet config command packet containing the parameters
+ */
+void pisa_cdconf_cb_server_add(pisa_conf_packet *packet)
+{
+       pisa_conf_serveradd *serveradd;
+
+       PISA_INFO("Got a server add request.\n");
+
+       assert(packet);
+       serveradd = &packet->body.request.rdata.serveradd;
+}
+
+/**
+ * Parse a pisacdconf service line and send out a packet to the client daemon.
+ * @param argc number of arguments
+ * @param argv array of arguments
+ * @return 0 on success, 1 on general error, 2 on specific error.
+ */
+static int pisa_cdconf_parse_service(int argc, char *argv[])
+{
+       pisa_conf_packet *packet;
+       pisa_conf_serviceadd *serviceadd;
+
+       if (argc != 3) {
+               PISA_ERROR("'service' needs 3 arguments.\n");
+               return 2;
+       }
+
+       packet = pisa_conf_packet_new_request();
+       serviceadd = &packet->body.request.rdata.serviceadd;
+       packet->body.request.header.type = htons(PISA_CONF_REQUEST_SERVICE_ADD);
+       pisa_conf_packet_add_len(packet, sizeof(pisa_conf_serviceadd));
+
+       if (inet_pton(AF_INET6, argv[0], &serviceadd->hit) != 1) {
+               PISA_ERROR("HIT could not be parsed.\n");
+               return 2;
+       }
+       if (inet_pton(AF_INET, argv[1], &serviceadd->local) != 1) {
+               PISA_ERROR("local could not be parsed.\n");
+               return 2;
+       }
+       if (inet_pton(AF_INET, argv[2], &serviceadd->remote) != 1) {
+               PISA_ERROR("remote could not be parsed.\n");
+               return 2;
+       }
+
+       pisa_conf_send_packet(packet);
+       free(packet);
+
+       return 0;
+}
+
+/**
+ * Handle a pisacdconf service add request.
+ * @param packet config command packet containing the parameters
+ */
+void pisa_cdconf_cb_service_add(pisa_conf_packet *packet)
+{
+       pisa_conf_serviceadd *serviceadd;
+       
+       PISA_INFO("Got a service add request.\n");
+
+       assert(packet);
+       serviceadd = &packet->body.request.rdata.serviceadd;
+}
 
 /**
  * Parse a pisacdconf line and send out a packet to the client daemon.
@@ -39,10 +151,10 @@
        if (common_result != 1)
                return common_result;
 
-/*
-       if (!strcmp("reload", argv[0]))
-               return pisa_sdconf_parse_reload(argc - 1, &argv[1]);
-*/
+       if (!strcmp("server", argv[0]))
+               return pisa_cdconf_parse_server(argc - 1, &argv[1]);
+       if (!strcmp("service", argv[0]))
+               return pisa_cdconf_parse_service(argc - 1, &argv[1]);
 
        return 1;
 }

Modified: trunk/client/pisacd/pisacdconf.h
==============================================================================
--- trunk/client/pisacd/pisacdconf.h    Thu Aug 20 16:23:09 2009        (r839)
+++ trunk/client/pisacd/pisacdconf.h    Fri Aug 21 12:13:36 2009        (r840)
@@ -15,4 +15,8 @@
 
 int pisa_cdconf_parse(int argc, char *argv[]);
 
+/* handler functions */
+void pisa_cdconf_cb_server_add(pisa_conf_packet *packet);
+void pisa_cdconf_cb_service_add(pisa_conf_packet *packet);
+
 #endif /* PISA_CDCONF_H */

Modified: trunk/client/pisacd/pisaconftool.c
==============================================================================
--- trunk/client/pisacd/pisaconftool.c  Thu Aug 20 16:23:09 2009        (r839)
+++ trunk/client/pisacd/pisaconftool.c  Fri Aug 21 12:13:36 2009        (r840)
@@ -16,7 +16,8 @@
 
 const char *usage_text =
 "Client options:\n"
-"\tnone\n"
+"\tserver\t\t: Add a connection (HIT relay|service|legacyrouter)\n"
+"\tservice\t\t: Add NAT mapping (HIT local-IPv4 remote-IPv4)\n"
 ;
 
 extern int pisa_conf_dst_port;

Modified: trunk/include/pisaconf.h
==============================================================================
--- trunk/include/pisaconf.h    Thu Aug 20 16:23:09 2009        (r839)
+++ trunk/include/pisaconf.h    Fri Aug 21 12:13:36 2009        (r840)
@@ -15,12 +15,15 @@
 #define PISACONF_H
 
 #include <stdint.h>
+#include <netinet/in.h>
 
 #define PISA_CONF_PACKET_REQUEST 1
 
 #define PISA_CONF_REQUEST_RELOAD_CONF  1
 #define PISA_CONF_REQUEST_DEBUGLEVEL   2
 #define PISA_CONF_REQUEST_DEBUGMASK    3
+#define PISA_CONF_REQUEST_SERVER_ADD   4
+#define PISA_CONF_REQUEST_SERVICE_ADD  5
 
 #define PISA_CONF_PORT_SD 5005
 #define PISA_CONF_PORT_CD 5006
@@ -40,6 +43,17 @@
 } __attribute__ ((packed)) pisa_conf_debugmask;
 
 typedef struct {
+       uint8_t type; /* use PISA_CONTYPE_* */
+       struct in6_addr hit;
+} __attribute__ ((packed)) pisa_conf_serveradd;
+
+typedef struct {
+       struct in6_addr hit;
+       struct in_addr local;
+       struct in_addr remote;
+} __attribute__ ((packed)) pisa_conf_serviceadd;
+
+typedef struct {
        uint16_t type; /* use PISA_CONF_REQUEST_* */
 } __attribute__ ((packed)) pisa_conf_request_header;
 
@@ -48,6 +62,8 @@
        union {
                pisa_conf_debuglevel debuglevel;
                pisa_conf_debugmask debugmask;
+               pisa_conf_serveradd serveradd;
+               pisa_conf_serviceadd serviceadd;
        } rdata;
 } __attribute__ ((packed)) pisa_conf_request;
 
@@ -74,6 +90,8 @@
        pisa_conf_handle_cb reload_conf;
        pisa_conf_handle_cb debuglevel;
        pisa_conf_handle_cb debugmask;
+       pisa_conf_handle_cb serveradd;
+       pisa_conf_handle_cb serviceadd;
 } pisa_conf_handle_func_set;
 
 pisa_conf_packet *pisa_conf_packet_new_request(void);

Modified: trunk/libpisa/pisaconf.c
==============================================================================
--- trunk/libpisa/pisaconf.c    Thu Aug 20 16:23:09 2009        (r839)
+++ trunk/libpisa/pisaconf.c    Fri Aug 21 12:13:36 2009        (r840)
@@ -45,6 +45,12 @@
                case PISA_CONF_REQUEST_DEBUGMASK:
                        f = conf_handle_func_set.debugmask;
                        break;
+               case PISA_CONF_REQUEST_SERVER_ADD:
+                       f = conf_handle_func_set.serveradd;
+                       break;
+               case PISA_CONF_REQUEST_SERVICE_ADD:
+                       f = conf_handle_func_set.serviceadd;
+                       break;
                default:
                        PISA_ERROR("Received unknown config request.\n");
                        break;
@@ -189,10 +195,10 @@
        if ((fd = pisa_conf_open_client_socket(pisa_conf_dst_port)) == -1)
                return 1;
 
-       sent = send(fd, packet, sizeof(pisa_conf_packet), 0);
+       sent = send(fd, packet, ntohs(packet->header.len), 0);
         close(fd);
 
-       if (sent == -1 || sent != sizeof(pisa_conf_packet))
+       if (sent == -1 || sent != ntohs(packet->header.len))
                return 1;
        
        PISA_DEBUG(PL_CONFIG, "Sent %i bytes.\n", sent);

Modified: trunk/trust-point/pisasd/pisasdconf.c
==============================================================================
--- trunk/trust-point/pisasd/pisasdconf.c       Thu Aug 20 16:23:09 2009        
(r839)
+++ trunk/trust-point/pisasd/pisasdconf.c       Fri Aug 21 12:13:36 2009        
(r840)
@@ -31,7 +31,7 @@
        pisa_conf_packet *packet;
 
        if (argc != 0) {
-               PISA_ERROR("Reload doesn't accept any arguments.\n");
+               PISA_ERROR("'reload' doesn't accept any arguments.\n");
                return 2;
        }
 

Other related posts:

  • » [pisa-src] r840 - in trunk: client/pisacd include libpisa trust-point/pisasd - Thomas Jansen