return control_return(c, type, 0);
}
-bool control_h(connection_t *c, char *request) {
+bool control_h(connection_t *c, const char *request) {
int type;
if(!c->status.control || c->allow_request != CONTROL) {
/* Jumptable for the request handlers */
-static bool (*request_handlers[])(connection_t *, char *) = {
+static bool (*request_handlers[])(connection_t *, const char *) = {
id_h, metakey_h, challenge_h, chal_reply_h, ack_h,
status_h, error_h, termreq_h,
ping_h, pong_h,
return send_meta(c, request, len);
}
-void forward_request(connection_t *from, char *request) {
- /* Note: request is not zero terminated anymore after a call to this function! */
+void forward_request(connection_t *from, const char *request) {
logger(DEBUG_META, LOG_DEBUG, "Forwarding %s from %s (%s): %s", request_name[atoi(request)], from->name, from->hostname, request);
+ // Create a temporary newline-terminated copy of the request
int len = strlen(request);
- request[len++] = '\n';
- broadcast_meta(from, request, len);
+ char tmp[len + 1];
+ memcpy(tmp, request, len);
+ tmp[len] = '\n';
+ broadcast_meta(from, tmp, len);
}
-bool receive_request(connection_t *c, char *request) {
+bool receive_request(connection_t *c, const char *request) {
int reqno = atoi(request);
if(reqno || *request == '0') {
static void free_past_request(past_request_t *r) {
if(r->request)
- free(r->request);
+ free((char *)r->request);
free(r);
}
static struct event past_request_event;
-bool seen_request(char *request) {
+bool seen_request(const char *request) {
past_request_t *new, p = {NULL};
p.request = request;
} request_t;
typedef struct past_request_t {
- char *request;
+ const char *request;
time_t firstseen;
} past_request_t;
/* Basic functions */
extern bool send_request(struct connection_t *, const char *, ...) __attribute__ ((__format__(printf, 2, 3)));
-extern void forward_request(struct connection_t *, char *);
-extern bool receive_request(struct connection_t *, char *);
+extern void forward_request(struct connection_t *, const char *);
+extern bool receive_request(struct connection_t *, const char *);
extern bool check_id(const char *);
extern void init_requests(void);
extern void exit_requests(void);
-extern bool seen_request(char *);
+extern bool seen_request(const char *);
/* Requests */
extern bool send_chal_reply(struct connection_t *);
extern bool send_ack(struct connection_t *);
extern bool send_status(struct connection_t *, int, const char *);
-extern bool send_error(struct connection_t *, int,const char *);
+extern bool send_error(struct connection_t *, int, const char *);
extern bool send_termreq(struct connection_t *);
extern bool send_ping(struct connection_t *);
extern bool send_pong(struct connection_t *);
/* Request handlers */
-extern bool id_h(struct connection_t *, char *);
-extern bool metakey_h(struct connection_t *, char *);
-extern bool challenge_h(struct connection_t *, char *);
-extern bool chal_reply_h(struct connection_t *, char *);
-extern bool ack_h(struct connection_t *, char *);
-extern bool status_h(struct connection_t *, char *);
-extern bool error_h(struct connection_t *, char *);
-extern bool termreq_h(struct connection_t *, char *);
-extern bool ping_h(struct connection_t *, char *);
-extern bool pong_h(struct connection_t *, char *);
-extern bool add_subnet_h(struct connection_t *, char *);
-extern bool del_subnet_h(struct connection_t *, char *);
-extern bool add_edge_h(struct connection_t *, char *);
-extern bool del_edge_h(struct connection_t *, char *);
-extern bool key_changed_h(struct connection_t *, char *);
-extern bool req_key_h(struct connection_t *, char *);
-extern bool ans_key_h(struct connection_t *, char *);
-extern bool tcppacket_h(struct connection_t *, char *);
-extern bool control_h(struct connection_t *, char *);
+extern bool id_h(struct connection_t *, const char *);
+extern bool metakey_h(struct connection_t *, const char *);
+extern bool challenge_h(struct connection_t *, const char *);
+extern bool chal_reply_h(struct connection_t *, const char *);
+extern bool ack_h(struct connection_t *, const char *);
+extern bool status_h(struct connection_t *, const char *);
+extern bool error_h(struct connection_t *, const char *);
+extern bool termreq_h(struct connection_t *, const char *);
+extern bool ping_h(struct connection_t *, const char *);
+extern bool pong_h(struct connection_t *, const char *);
+extern bool add_subnet_h(struct connection_t *, const char *);
+extern bool del_subnet_h(struct connection_t *, const char *);
+extern bool add_edge_h(struct connection_t *, const char *);
+extern bool del_edge_h(struct connection_t *, const char *);
+extern bool key_changed_h(struct connection_t *, const char *);
+extern bool req_key_h(struct connection_t *, const char *);
+extern bool ans_key_h(struct connection_t *, const char *);
+extern bool tcppacket_h(struct connection_t *, const char *);
+extern bool control_h(struct connection_t *, const char *);
#endif /* __TINC_PROTOCOL_H__ */
return send_request(c, "%d %s %d.%d", ID, myself->connection->name, myself->connection->protocol_major, minor);
}
-bool id_h(connection_t *c, char *request) {
+bool id_h(connection_t *c, const char *request) {
char name[MAX_STRING_SIZE];
if(sscanf(request, "%*d " MAX_STRING " %d.%d", name, &c->protocol_major, &c->protocol_minor) < 2) {
return result;
}
-bool metakey_h(connection_t *c, char *request) {
+bool metakey_h(connection_t *c, const char *request) {
char hexkey[MAX_STRING_SIZE];
int cipher, digest, maclength, compression;
size_t len = rsa_size(&myself->connection->rsa);
return send_request(c, "%d %s", CHALLENGE, buffer);
}
-bool challenge_h(connection_t *c, char *request) {
+bool challenge_h(connection_t *c, const char *request) {
char buffer[MAX_STRING_SIZE];
size_t len = rsa_size(&myself->connection->rsa);
size_t digestlen = digest_length(&c->indigest);
return send_request(c, "%d %s", CHAL_REPLY, buffer);
}
-bool chal_reply_h(connection_t *c, char *request) {
+bool chal_reply_h(connection_t *c, const char *request) {
char hishash[MAX_STRING_SIZE];
if(sscanf(request, "%*d " MAX_STRING, hishash) != 1) {
}
}
-static bool upgrade_h(connection_t *c, char *request) {
+static bool upgrade_h(connection_t *c, const char *request) {
char pubkey[MAX_STRING_SIZE];
if(sscanf(request, "%*d " MAX_STRING, pubkey) != 1) {
return send_termreq(c);
}
-bool ack_h(connection_t *c, char *request) {
+bool ack_h(connection_t *c, const char *request) {
if(c->protocol_minor == 1)
return upgrade_h(c, request);
return x;
}
-bool add_edge_h(connection_t *c, char *request) {
+bool add_edge_h(connection_t *c, const char *request) {
edge_t *e;
node_t *from, *to;
char from_name[MAX_STRING_SIZE];
e->from->name, e->to->name);
}
-bool del_edge_h(connection_t *c, char *request) {
+bool del_edge_h(connection_t *c, const char *request) {
edge_t *e;
char from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE];
}
}
-bool key_changed_h(connection_t *c, char *request) {
+bool key_changed_h(connection_t *c, const char *request) {
char name[MAX_STRING_SIZE];
node_t *n;
return send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, to->name, experimental ? 1 : 0);
}
-bool req_key_h(connection_t *c, char *request) {
+bool req_key_h(connection_t *c, const char *request) {
char from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE];
node_t *from, *to;
to->incompression);
}
-bool ans_key_h(connection_t *c, char *request) {
+bool ans_key_h(connection_t *c, const char *request) {
char from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE];
char key[MAX_STRING_SIZE];
return send_request(c, "%d %d %s", STATUS, statusno, statusstring);
}
-bool status_h(connection_t *c, char *request) {
+bool status_h(connection_t *c, const char *request) {
int statusno;
char statusstring[MAX_STRING_SIZE];
return send_request(c, "%d %d %s", ERROR, err, errstring);
}
-bool error_h(connection_t *c, char *request) {
+bool error_h(connection_t *c, const char *request) {
int err;
char errorstring[MAX_STRING_SIZE];
return send_request(c, "%d", TERMREQ);
}
-bool termreq_h(connection_t *c, char *request) {
+bool termreq_h(connection_t *c, const char *request) {
return false;
}
return send_request(c, "%d", PING);
}
-bool ping_h(connection_t *c, char *request) {
+bool ping_h(connection_t *c, const char *request) {
return send_pong(c);
}
return send_request(c, "%d", PONG);
}
-bool pong_h(connection_t *c, char *request) {
+bool pong_h(connection_t *c, const char *request) {
c->status.pinged = false;
/* Succesful connection, reset timeout if this is an outgoing connection. */
return send_meta(c, (char *)packet->data, packet->len);
}
-bool tcppacket_h(connection_t *c, char *request) {
+bool tcppacket_h(connection_t *c, const char *request) {
short int len;
if(sscanf(request, "%*d %hd", &len) != 1) {
return send_request(c, "%d %x %s %s", ADD_SUBNET, rand(), subnet->owner->name, netstr);
}
-bool add_subnet_h(connection_t *c, char *request) {
+bool add_subnet_h(connection_t *c, const char *request) {
char subnetstr[MAX_STRING_SIZE];
char name[MAX_STRING_SIZE];
node_t *owner;
return send_request(c, "%d %x %s %s", DEL_SUBNET, rand(), s->owner->name, netstr);
}
-bool del_subnet_h(connection_t *c, char *request) {
+bool del_subnet_h(connection_t *c, const char *request) {
char subnetstr[MAX_STRING_SIZE];
char name[MAX_STRING_SIZE];
node_t *owner;