05_dccp-supported-ccid-lookup.diff
authorGerrit Renker <grenker@cscs.ch>
Thu, 25 Feb 2010 16:05:45 +0000 (17:05 +0100)
committerAndre Noll <maan@systemlinux.org>
Thu, 25 Feb 2010 16:05:45 +0000 (17:05 +0100)
This adds a self-contained function to return the space-separated list of
CCIDs available on the para_server. Visible via 'para_client si'.

Since feature negotiation for CCIDs is supported only from v2.6.30-rc1
(released 7th April 2009), a more recent kernel (>= 2.6.30) is needed to
support this feature, as well as subsequent per-connection use of CCIDs.

Note: This patch still uses a hardcoded upper bound (DCCP_MAX_HOST_CCIDS),
      support dynamically detecting the number of CCIDs will be in 2.6.33.

dccp_send.c
net.c
net.h

index d2f81dd9168023df27a1fefdb883e3234382c1cc..94719f0443c2081842c14e6e153262e551e2903c 100644 (file)
@@ -104,9 +104,33 @@ static int dccp_com_allow(struct sender_command_data *scd)
        return 1;
 }
 
+/**
+ * Return list of available CCIDs or warning, in static buffer.
+ */
+static const char *dccp_list_available_ccids(void)
+{
+       uint8_t ccids[DCCP_MAX_HOST_CCIDS];
+       uint8_t nccids = sizeof(ccids), i, len;
+       /* Worst case length: n * 3 digits + n-1 spaces + '\0' */
+       static char list[DCCP_MAX_HOST_CCIDS * 4];
+
+       if (dccp_available_ccids(ccids, &nccids) == NULL) {
+               snprintf(list, sizeof(list), "Unable to query available CCIDs");
+       } else {
+               for (i = len = 0; i < nccids; i++)
+                       len += snprintf(list + len, sizeof(list) - len,
+                                       "%s%d", i ? " " : "", ccids[i]);
+       }
+       return list;
+}
+
 static char *dccp_info(void)
 {
-       return get_sender_info(dss, "dccp");
+       char *info = get_sender_info(dss, "dccp");
+       char *ret  = make_message("%s" "\tsupported ccids: %s\n",
+                                 info, dccp_list_available_ccids());
+       free(info);
+       return ret;
 }
 
 /**
diff --git a/net.c b/net.c
index 6ab96215df880dc04eea0f6f90c48fd385720816..b83ab8c61d34c3a52f8e0f35dfa63d05c3584f21 100644 (file)
--- a/net.c
+++ b/net.c
@@ -661,6 +661,33 @@ int para_accept(int fd, void *addr, socklen_t size)
        return new_fd < 0? -ERRNO_TO_PARA_ERROR(errno) : new_fd;
 }
 
+/**
+ * Probe the list of DCCP CCIDs supported locally by the host.
+ * \param ccids Array to be filled in.
+ * \param nccids Length of \a ccids.
+ * \return Pointer to \a ccids, NULL on failure.
+ *
+ * NB: This feature is only available on Linux > 2.6.30; on older kernels
+ * ENOPROTOOPT ("Protocol not available") will be returned.
+ */
+const uint8_t *dccp_available_ccids(uint8_t *ccids, uint8_t *nccids)
+{
+       int fd = makesock(AF_UNSPEC, IPPROTO_DCCP, 0, NULL, 0);
+
+       if (fd < 0)
+               return NULL;
+
+       if (getsockopt(fd, SOL_DCCP, DCCP_SOCKOPT_AVAILABLE_CCIDS,
+                                       ccids, (socklen_t *)nccids) < 0) {
+               PARA_ERROR_LOG("No DCCP_SOCKOPT_AVAILABLE_CCIDS: %s\n",
+                               strerror(errno));
+               *nccids = 0;
+       }
+       close(fd);
+
+       return *nccids ? ccids : NULL;
+}
+
 /**
  * Prepare a structure for \p AF_UNIX socket addresses.
  *
diff --git a/net.h b/net.h
index 88b8d431ed6453e11ddfa7ac021ee84f8e54c185..66bf875568eadd9fe07587e31edc5539e472575d 100644 (file)
--- a/net.h
+++ b/net.h
@@ -100,3 +100,10 @@ int create_remote_socket(const char *name);
 int recv_cred_buffer(int, char *, size_t);
 ssize_t send_cred_buffer(int, char*);
 int recv_pattern(int fd, const char *pattern, size_t bufsize);
+
+/**
+ * Functions and definitions to support \p IPPROTO_DCCP
+ */
+/** Hardcoded maximum number of separate CCID modules compiled into a host */
+#define DCCP_MAX_HOST_CCIDS    20
+extern const uint8_t *dccp_available_ccids(uint8_t *ccids, uint8_t *nccids);