From 306d23c6ce07f55b0b281fe81503e4becee55f11 Mon Sep 17 00:00:00 2001 From: sr Date: Wed, 7 Nov 2012 19:08:58 +0100 Subject: [SERVER] Remove unix socket support for RPC interface [SERVER] Restructure RPC functions, add helpers --- src/kernel/net.c | 13 +-- src/server/ipc.c | 240 ++++++++++++++++++++++----------------------------- src/server/ipc.h | 16 ++-- src/server/job.c | 8 +- src/server/net.c | 6 +- src/server/server.c | 2 +- src/server/xmlutil.c | 16 ++++ src/server/xmlutil.h | 1 + src/types.h | 4 +- 9 files changed, 146 insertions(+), 160 deletions(-) (limited to 'src') diff --git a/src/kernel/net.c b/src/kernel/net.c index d6ebb32..f225189 100644 --- a/src/kernel/net.c +++ b/src/kernel/net.c @@ -183,7 +183,7 @@ int dnbd3_net_connect(dnbd3_device_t *dev) error_dev("FATAL: Connection to host failed."); // Request filesize dnbd3_request.magic = dnbd3_packet_magic; - dnbd3_request.cmd = CMD_GET_SIZE; + dnbd3_request.cmd = CMD_SELECT_IMAGE; iov[0].iov_base = &dnbd3_request; iov[0].iov_len = sizeof(dnbd3_request); serializer_reset_write(&dev->payload_buffer); @@ -204,13 +204,13 @@ int dnbd3_net_connect(dnbd3_device_t *dev) error_dev("FATAL: Received corrupted reply header after CMD_SIZE_REQUEST."); // check reply header fixup_reply(dnbd3_reply); - if (dnbd3_reply.cmd != CMD_GET_SIZE || dnbd3_reply.size < 3 || dnbd3_reply.size > MAX_PAYLOAD || dnbd3_reply.magic != dnbd3_packet_magic) + if (dnbd3_reply.cmd != CMD_SELECT_IMAGE || dnbd3_reply.size < 3 || dnbd3_reply.size > MAX_PAYLOAD || dnbd3_reply.magic != dnbd3_packet_magic) error_dev("FATAL: Received invalid reply to CMD_SIZE_REQUEST, image doesn't exist on server."); // receive reply payload iov[0].iov_base = &dev->payload_buffer; iov[0].iov_len = dnbd3_reply.size; if (kernel_recvmsg(dev->sock, &msg, iov, 1, dnbd3_reply.size, msg.msg_flags) != dnbd3_reply.size) - error_dev("FATAL: Cold not read CMD_GET_SIZE payload on handshake."); + error_dev("FATAL: Cold not read CMD_SELECT_IMAGE payload on handshake."); // handle/check reply payload serializer_reset_read(&dev->payload_buffer, dnbd3_reply.size); dev->cur_server.protocol_version = serializer_get_uint16(&dev->payload_buffer); @@ -298,7 +298,8 @@ error: int dnbd3_net_disconnect(dnbd3_device_t *dev) { - debug_dev("INFO: Disconnecting device."); + if (dev->cur_server.host.port) + debug_dev("INFO: Disconnecting device."); dev->disconnecting = 1; @@ -514,7 +515,7 @@ int dnbd3_net_discover(void *data) goto error; // Request filesize - dnbd3_request.cmd = CMD_GET_SIZE; + dnbd3_request.cmd = CMD_SELECT_IMAGE; iov[0].iov_base = &dnbd3_request; iov[0].iov_len = sizeof(dnbd3_request); serializer_reset_write(payload); @@ -535,7 +536,7 @@ int dnbd3_net_discover(void *data) if (kernel_recvmsg(sock, &msg, iov, 1, sizeof(dnbd3_reply), msg.msg_flags) != sizeof(dnbd3_reply)) error_alt("ERROR: Receiving image size packet (header) failed (discover)."); fixup_reply(dnbd3_reply); - if (dnbd3_reply.magic != dnbd3_packet_magic || dnbd3_reply.cmd != CMD_GET_SIZE || dnbd3_reply.size < 4) + if (dnbd3_reply.magic != dnbd3_packet_magic || dnbd3_reply.cmd != CMD_SELECT_IMAGE || dnbd3_reply.size < 4) error_alt("ERROR: Content of image size packet (header) mismatched (discover)."); // receive data diff --git a/src/server/ipc.c b/src/server/ipc.c index 5ee1194..a345794 100644 --- a/src/server/ipc.c +++ b/src/server/ipc.c @@ -60,6 +60,7 @@ static int ipc_receive(int client_sock); static int get_highest_fd(GSList *sockets); static int is_password_correct(xmlDocPtr doc); static int get_terminal_width(); +static int ipc_send_reply(int sock, dnbd3_ipc_t* header, int result_code, xmlDocPtr payload); static int get_highest_fd(GSList *sockets) { @@ -90,7 +91,6 @@ void *dnbd3_ipc_mainloop() return NULL; } -#ifdef IPC_TCP struct sockaddr_in server, client; socklen_t len = sizeof(client); @@ -122,48 +122,6 @@ void *dnbd3_ipc_mainloop() perror("ERROR: IPC listen"); exit(EXIT_FAILURE); } -#else - struct sockaddr_un server, client; - socklen_t len = sizeof(client); - - // Create socket - if ((server_sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) - { - perror("ERROR: IPC socket"); - exit(EXIT_FAILURE); - } - - server.sun_family = AF_UNIX; - strcpy(server.sun_path, UNIX_SOCKET); - unlink(UNIX_SOCKET); - - // Bind to socket - if (bind(server_sock, &server, sizeof(server.sun_family) + strlen(server.sun_path)) < 0) - { - perror("ERROR: IPC bind"); - exit(EXIT_FAILURE); - } - - // Listen on socket - if (listen(server_sock, 5) < 0) - { - perror("ERROR: IPC listen"); - exit(EXIT_FAILURE); - } - - // Set groupID and permissions on ipc socket - struct group *grp; - grp = getgrnam(UNIX_SOCKET_GROUP); - if (grp == NULL) - { - memlogf("WARN: Group '%s' not found.\n", UNIX_SOCKET_GROUP); - } - else - { - chmod(UNIX_SOCKET, 0775); - chown(UNIX_SOCKET, -1, grp->gr_gid); - } -#endif // Run connection-accepting loop @@ -311,12 +269,10 @@ static int ipc_receive(int client_sock) uint32_t cmd; - int ret, locked; + int ret, locked = 0; int return_value = 0; xmlDocPtr docReply = NULL, docRequest = NULL; xmlNodePtr root_node, parent_node, tmp_node, log_parent_node, log_node, server_node; - xmlChar *xmlbuff; - int buffersize; ret = recv(client_sock, &header, sizeof(header), MSG_WAITALL); if (ret != sizeof(header)) @@ -324,7 +280,7 @@ static int ipc_receive(int client_sock) cmd = ntohl(header.cmd); // Leave header.cmd in network byte order for reply header.size = ntohl(header.size); - header.error = htonl(ERROR_UNSPECIFIED_ERROR); // Default value of error, so remember to set it for the reply if call succeeded + int rpc_error = ERROR_UNSPECIFIED_ERROR; // Default value of error, so remember to set it for the reply if call succeeded if (header.size != 0) { @@ -345,28 +301,20 @@ static int ipc_receive(int client_sock) case IPC_EXIT: memlogf("[INFO] Server shutdown by IPC request"); header.size = ntohl(0); - header.error = ntohl(0); return_value = send_data(client_sock, &header, sizeof(header)); dnbd3_cleanup(); break; - case IPC_INFO: - locked = 0; - xmlbuff = NULL; - docReply = xmlNewDoc(BAD_CAST "1.0"); - if (docReply == NULL) - goto get_info_reply_cleanup; - root_node = xmlNewNode(NULL, BAD_CAST "data"); - if (root_node == NULL) - goto get_info_reply_cleanup; - xmlDocSetRootElement(docReply, root_node); + case IPC_IMG_LIST: + if (!createXmlDoc(&docReply, &root_node, "data")) + goto case_end; xmlNewTextChild(root_node, NULL, BAD_CAST "defaultns", BAD_CAST _local_namespace); // Images parent_node = xmlNewNode(NULL, BAD_CAST "images"); if (parent_node == NULL) - goto get_info_reply_cleanup; + goto case_end; xmlAddChild(root_node, parent_node); locked = 1; pthread_spin_lock(&_spinlock); @@ -375,7 +323,7 @@ static int ipc_receive(int client_sock) const dnbd3_image_t *image = iterator->data; tmp_node = xmlNewNode(NULL, BAD_CAST "image"); if (tmp_node == NULL) - goto get_info_reply_cleanup; + goto case_end; xmlNewProp(tmp_node, BAD_CAST "name", BAD_CAST image->config_group); sprintf(strbuffer, "%u", (unsigned int)image->atime); xmlNewProp(tmp_node, BAD_CAST "atime", BAD_CAST strbuffer); @@ -401,10 +349,18 @@ static int ipc_receive(int client_sock) pthread_spin_unlock(&_spinlock); locked = 0; + // Dump and send + rpc_error = 0; + break; + + case IPC_CLIENT_LIST: + if (!createXmlDoc(&docReply, &root_node, "data")) + goto case_end; + // Clients parent_node = xmlNewNode(NULL, BAD_CAST "clients"); if (parent_node == NULL) - goto get_info_reply_cleanup; + goto case_end; xmlAddChild(root_node, parent_node); locked = 1; pthread_spin_lock(&_spinlock); @@ -415,21 +371,31 @@ static int ipc_receive(int client_sock) { tmp_node = xmlNewNode(NULL, BAD_CAST "client"); if (tmp_node == NULL) - goto get_info_reply_cleanup; + goto case_end; *strbuffer = '\0'; host_to_string(&client->host, strbuffer, STRBUFLEN); - xmlNewProp(tmp_node, BAD_CAST "ip", BAD_CAST strbuffer); - xmlNewProp(tmp_node, BAD_CAST "file", BAD_CAST client->image->file); + xmlNewProp(tmp_node, BAD_CAST "address", BAD_CAST strbuffer); + xmlNewProp(tmp_node, BAD_CAST "image", BAD_CAST client->image->config_group); + sprintf(strbuffer, "%d", client->image->rid); + xmlNewProp(tmp_node, BAD_CAST "rid", BAD_CAST strbuffer); xmlAddChild(parent_node, tmp_node); } } pthread_spin_unlock(&_spinlock); locked = 0; + // Dump and send + rpc_error = 0; + break; + + case IPC_TRUSTED_LIST: + if (!createXmlDoc(&docReply, &root_node, "data")) + goto case_end; + // Trusted servers parent_node = xmlNewNode(NULL, BAD_CAST "trusted"); if (parent_node == NULL) - goto get_info_reply_cleanup; + goto case_end; xmlAddChild(root_node, parent_node); locked = 1; pthread_spin_lock(&_spinlock); @@ -440,10 +406,10 @@ static int ipc_receive(int client_sock) { tmp_node = xmlNewNode(NULL, BAD_CAST "server"); if (tmp_node == NULL) - goto get_info_reply_cleanup; + goto case_end; xmlNodePtr namespace_root = xmlNewNode(NULL, BAD_CAST "namespaces"); if (namespace_root == NULL) - goto get_info_reply_cleanup; + goto case_end; host_to_string(&server->host, strbuffer, STRBUFLEN); xmlNewProp(tmp_node, BAD_CAST "address", BAD_CAST strbuffer); if (server->comment) @@ -453,7 +419,7 @@ static int ipc_receive(int client_sock) const dnbd3_namespace_t *ns = iterator2->data; server_node = xmlNewNode(NULL, BAD_CAST "namespace"); if (server_node == NULL) - goto get_info_reply_cleanup; + goto case_end; xmlAddChild(namespace_root, server_node); xmlNewProp(server_node, BAD_CAST "name", BAD_CAST ns->name); if (ns->auto_replicate) @@ -468,44 +434,38 @@ static int ipc_receive(int client_sock) pthread_spin_unlock(&_spinlock); locked = 0; + // Dump and send + rpc_error = 0; + break; + + case IPC_GET_LOG: + if (!createXmlDoc(&docReply, &root_node, "data")) + goto case_end; + // Log log_parent_node = xmlNewChild(root_node, NULL, BAD_CAST "log", NULL); if (log_parent_node == NULL) - goto get_info_reply_cleanup; + goto case_end; char *log = fetchlog(0); if (log == NULL) - log = "LOG IS NULL"; + log = strdup("LOG IS NULL"); log_node = xmlNewCDataBlock(docReply, BAD_CAST log, strlen(log)); + free(log); if (log_node == NULL) - goto get_info_reply_cleanup; + goto case_end; xmlAddChild(log_parent_node, log_node); // Dump and send - xmlDocDumpFormatMemory(docReply, &xmlbuff, &buffersize, 1); - header.size = htonl(buffersize); - header.error = htonl(0); - -get_info_reply_cleanup: - if (locked) - pthread_spin_unlock(&_spinlock); - // Send reply - return_value = send_data(client_sock, &header, sizeof(header)); - if (return_value && xmlbuff) - return_value = send_data(client_sock, xmlbuff, buffersize); - // Cleanup - xmlFree(xmlbuff); - free(log); + rpc_error = 0; break; - case IPC_ADDIMG: - case IPC_DELIMG: + case IPC_ADD_IMG: + case IPC_DEL_IMG: if (docRequest) { if (!is_password_correct(docRequest)) { - header.error = htonl(ERROR_WRONG_PASSWORD); - header.size = htonl(0); - return_value = send_data(client_sock, &header, sizeof(header)); + rpc_error = ERROR_WRONG_PASSWORD; break; } @@ -526,47 +486,42 @@ get_info_reply_cleanup: image.cache_file = (char *)XML_GETPROP(cur, "cache"); if (image.file && !file_exists(image.file)) { - header.error = htonl(ERROR_FILE_NOT_FOUND); + rpc_error = ERROR_FILE_NOT_FOUND; } else if (image.cache_file && !file_writable(image.cache_file)) { - header.error = htonl(ERROR_NOT_WRITABLE); + rpc_error = ERROR_NOT_WRITABLE; } else { if (image.config_group && rid_str) { image.rid = atoi(rid_str); - if (cmd == IPC_ADDIMG) - header.error = htonl(dnbd3_add_image(&image)); + if (cmd == IPC_ADD_IMG) + rpc_error = dnbd3_add_image(&image); else - header.error = htonl(dnbd3_del_image(&image)); + rpc_error = dnbd3_del_image(&image); } else - header.error = htonl(ERROR_MISSING_ARGUMENT); + rpc_error = ERROR_MISSING_ARGUMENT; } FREE_POINTERLIST; } END_FOR_EACH; if (count == 0) - header.error = htonl(ERROR_MISSING_ARGUMENT); + rpc_error = ERROR_MISSING_ARGUMENT; } else - header.error = htonl(ERROR_INVALID_XML); + rpc_error = ERROR_INVALID_XML; - header.size = htonl(0); - printf("Code: %d\n", (int)ntohl(header.error)); - return_value = send_data(client_sock, &header, sizeof(header)); break; - case IPC_ADDNS: - case IPC_DELNS: + case IPC_ADD_NS: + case IPC_DEL_NS: if (docRequest) { if (!is_password_correct(docRequest)) { - header.error = htonl(ERROR_WRONG_PASSWORD); - header.size = htonl(0); - return_value = send_data(client_sock, &header, sizeof(header)); + rpc_error = ERROR_WRONG_PASSWORD; break; } @@ -577,14 +532,14 @@ get_info_reply_cleanup: if (cur->type != XML_ELEMENT_NODE) continue; NEW_POINTERLIST; - char *host = (char *)XML_GETPROP(cur, "server"); + char *host = (char *)XML_GETPROP(cur, "address"); char *ns = (char *)XML_GETPROP(cur, "name"); char *flags = (char *)XML_GETPROP(cur, "flags"); char *comment = (char *)XML_GETPROP(cur, "comment"); pthread_spin_lock(&_spinlock); if (host && ns) { - if (cmd == IPC_ADDNS) + if (cmd == IPC_ADD_NS) { dnbd3_trusted_server_t *server = dnbd3_get_trusted_server(host, TRUE, comment); if (server) @@ -603,20 +558,22 @@ get_info_reply_cleanup: } else - header.error = htonl(ERROR_INVALID_XML); + rpc_error = ERROR_INVALID_XML; - header.size = htonl(0); - return_value = send_data(client_sock, &header, sizeof(header)); break; default: memlogf("[ERROR] Unknown IPC command: %u", (unsigned int)header.cmd); - header.size = htonl(0); - header.error = htonl(ERROR_UNKNOWN_COMMAND); - return_value = send_data(client_sock, &header, sizeof(header)); + rpc_error = htonl(ERROR_UNKNOWN_COMMAND); break; } +case_end: + + if (locked) + pthread_spin_unlock(&_spinlock); + // Send reply + return_value = ipc_send_reply(client_sock, &header, rpc_error, docReply); xmlFreeDoc(docReply); xmlFreeDoc(docRequest); @@ -631,7 +588,6 @@ void dnbd3_ipc_send(int cmd) // Check version and initialize LIBXML_TEST_VERSION -#ifdef IPC_TCP struct sockaddr_in server; struct timeval client_timeout; @@ -658,38 +614,17 @@ void dnbd3_ipc_send(int cmd) perror("ERROR: IPC connect"); exit(EXIT_FAILURE); } -#else - struct sockaddr_un server; - - // Create socket - if ((client_sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) - { - perror("ERROR: IPC socket"); - exit(EXIT_FAILURE); - } - server.sun_family = AF_UNIX; - strcpy(server.sun_path, UNIX_SOCKET); - - // Connect to server - if (connect(client_sock, &server, sizeof(server.sun_family) + strlen(server.sun_path)) < 0) - { - perror("ERROR: IPC connect"); - exit(EXIT_FAILURE); - } -#endif // Send message dnbd3_ipc_t header; header.cmd = htonl(cmd); header.size = 0; - header.error = 0; send(client_sock, (char *)&header, sizeof(header), MSG_WAITALL); recv(client_sock, &header, sizeof(header), MSG_WAITALL); header.cmd = ntohl(header.cmd); header.size = ntohl(header.size); - header.error = ntohl(header.error); - if (cmd == IPC_INFO && header.size > 0) + if (cmd == IPC_IMG_LIST && header.size > 0) { char *buf = malloc(header.size + 1); size = recv(client_sock, buf, header.size, MSG_WAITALL); @@ -853,3 +788,34 @@ static int get_terminal_width() return 80; return w.ws_col; } + +#define RETBUFLEN 8000 +static char returnbuffer[RETBUFLEN]; +static int ipc_send_reply(int sock, dnbd3_ipc_t* header, int result_code, xmlDocPtr payload) +{ + if (result_code == 0 && payload != NULL) + { + // No error + xmlChar *xmlbuff = NULL; + int buffersize; + xmlDocDumpFormatMemory(payload, &xmlbuff, &buffersize, 1); + header->size = htonl(buffersize); + if (!send_data(sock, header, sizeof(*header))) + return FALSE; + if (xmlbuff) + return send_data(sock, xmlbuff, buffersize); + return TRUE; + } + // Error code, build xml struct (lazy shortcut) + int len = snprintf(returnbuffer, RETBUFLEN, "\n" + "\n" + "\n" + "", result_code, "TODO"); + if (len >= RETBUFLEN) + len = 10; + header->size = htonl(len); + header->cmd = htonl(IPC_ERROR); + if (!send_data(sock, header, sizeof(*header))) + return FALSE; + return send_data(sock, returnbuffer, len); +} diff --git a/src/server/ipc.h b/src/server/ipc.h index 87722d8..fabe6f8 100644 --- a/src/server/ipc.h +++ b/src/server/ipc.h @@ -25,11 +25,16 @@ #define IPC_EXIT 0 #define IPC_RELOAD 1 -#define IPC_INFO 2 -#define IPC_ADDIMG 3 -#define IPC_DELIMG 4 -#define IPC_ADDNS 5 -#define IPC_DELNS 6 +#define IPC_IMG_LIST 2 +#define IPC_ADD_IMG 3 +#define IPC_DEL_IMG 4 +#define IPC_ADD_NS 5 +#define IPC_DEL_NS 6 +#define IPC_CLIENT_LIST 7 +#define IPC_TRUSTED_LIST 8 +#define IPC_GET_LOG 9 +#define IPC_FIX_IMAGE 10 +#define IPC_ERROR 11 void *dnbd3_ipc_mainloop(); @@ -44,7 +49,6 @@ typedef struct uint32_t handle;// 4byte uint32_t cmd; // 4byte uint32_t size; // 4byte - uint32_t error; // 4byte } dnbd3_ipc_t; #pragma pack(0) diff --git a/src/server/job.c b/src/server/job.c index 5ac0721..d1f99b8 100644 --- a/src/server/job.c +++ b/src/server/job.c @@ -416,9 +416,8 @@ static void query_servers() // Send and receive info from server // Send message dnbd3_ipc_t header; - header.cmd = htonl(IPC_INFO); + header.cmd = htonl(IPC_IMG_LIST); header.size = 0; - header.error = 0; send(client_sock, (char *)&header, sizeof(header), 0); if (!recv_data(client_sock, &header, sizeof(header))) { @@ -427,10 +426,9 @@ static void query_servers() } header.cmd = ntohl(header.cmd); header.size = ntohl(header.size); - header.error = ntohl(header.error); - if (header.cmd != IPC_INFO || header.error != 0) + if (header.cmd != IPC_IMG_LIST) { - printf("[DEBUG] Error. Reply from other server was cmd:%d, error:%d\n", (int)header.cmd, (int)header.error); + printf("[DEBUG] Error. Reply from other server was cmd:%d, error:%d\n", (int)header.cmd, (int)-1); goto communication_error; } if (header.size > MAX_IPC_PAYLOAD) diff --git a/src/server/net.c b/src/server/net.c index a895f85..76deed6 100644 --- a/src/server/net.c +++ b/src/server/net.c @@ -147,10 +147,10 @@ void *dnbd3_handle_query(void *dnbd3_client) reply.magic = dnbd3_packet_magic; - // Receive first packet. This must be CMD_GET_SIZE by protocol specification + // Receive first packet. This must be CMD_SELECT_IMAGE by protocol specification if (recv_request_header(client->sock, &request)) { - if (request.cmd != CMD_GET_SIZE) + if (request.cmd != CMD_SELECT_IMAGE) { printf("[DEBUG] Client sent invalid handshake (%d). Dropping Client\n", (int)request.cmd); } @@ -198,7 +198,7 @@ void *dnbd3_handle_query(void *dnbd3_client) serializer_put_string(&payload, image->low_name); serializer_put_uint16(&payload, image->rid); serializer_put_uint64(&payload, image->filesize); - reply.cmd = CMD_GET_SIZE; + reply.cmd = CMD_SELECT_IMAGE; reply.size = serializer_get_written_length(&payload); if (!send_reply(client->sock, &reply, &payload)) { diff --git a/src/server/server.c b/src/server/server.c index 126ac5e..bd5f10a 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -189,7 +189,7 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; case 'i': printf("INFO: Requesting information...\n\n"); - dnbd3_ipc_send(IPC_INFO); + dnbd3_ipc_send(IPC_IMG_LIST); return EXIT_SUCCESS; case 'H': dnbd3_print_help(argv[0]); diff --git a/src/server/xmlutil.c b/src/server/xmlutil.c index 1718bfb..d1163a7 100644 --- a/src/server/xmlutil.c +++ b/src/server/xmlutil.c @@ -25,3 +25,19 @@ char *getTextFromPath(xmlDocPtr doc, char *xpath) xmlXPathFreeContext(xpathCtx); return retval; } + + +char createXmlDoc(xmlDocPtr *doc, xmlNodePtr* root, char* rootName) +{ + *doc = xmlNewDoc(BAD_CAST "1.0"); + if (*doc == NULL) + return 0; + *root = xmlNewNode(NULL, BAD_CAST rootName); + if (*root == NULL) + { + xmlFreeDoc(*doc); + return 0; + } + xmlDocSetRootElement(*doc, *root); + return 1; +} diff --git a/src/server/xmlutil.h b/src/server/xmlutil.h index fddb317..ecfa4c4 100644 --- a/src/server/xmlutil.h +++ b/src/server/xmlutil.h @@ -5,6 +5,7 @@ #include char *getTextFromPath(xmlDocPtr doc, char *xpath); +char createXmlDoc(xmlDocPtr *doc, xmlNodePtr* root, char* rootName); #define FOR_EACH_NODE(_doc, _path, _node) do { \ xmlXPathContextPtr _makro_xpathCtx = xmlXPathNewContext(_doc); \ diff --git a/src/types.h b/src/types.h index 22fbc50..f6eb5f4 100644 --- a/src/types.h +++ b/src/types.h @@ -32,7 +32,7 @@ #define IOCTL_REM_SRV _IO(0xab, 5) #if defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN) || (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) -const uint16_t dnbd3_packet_magic = (0x73 << 8) | (0x72); +static const uint16_t dnbd3_packet_magic = (0x73 << 8) | (0x72); // Flip bytes around on big endian when putting stuff on the net #define net_order_64(a) ((uint64_t)((((a) & 0xFFull) << 56) | (((a) & 0xFF00ull) << 40) | (((a) & 0xFF0000ull) << 24) | (((a) & 0xFF000000ull) << 8) | (((a) & 0xFF00000000ull) >> 8) | (((a) & 0xFF0000000000ull) >> 24) | (((a) & 0xFF000000000000ull) >> 40) | (((a) & 0xFF00000000000000ull) >> 56))) #define net_order_32(a) ((uint32_t)((((a) & (uint32_t)0xFF) << 24) | (((a) & (uint32_t)0xFF00) << 8) | (((a) & (uint32_t)0xFF0000) >> 8) | (((a) & (uint32_t)0xFF000000) >> 24))) @@ -82,7 +82,7 @@ typedef struct // network #define CMD_GET_BLOCK 1 -#define CMD_GET_SIZE 2 +#define CMD_SELECT_IMAGE 2 #define CMD_GET_SERVERS 3 #define CMD_ERROR 4 #define CMD_KEEPALIVE 5 -- cgit v1.2.3-55-g7522