diff options
author | Linus Nordberg <linus@nordberg.se> | 2013-01-24 15:19:43 +0100 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2013-01-24 15:19:43 +0100 |
commit | a11aab1d9b4ecd4e8c31a5002af142b1828a4016 (patch) | |
tree | 93a545d1c20f6650249be569917abc2531aecde4 /lib | |
parent | 451e4f8ef7b0b4a353318d68a42f1239ec9878e4 (diff) | |
parent | 1e3a2613b356bf542fd75c198e9c9813e24f08d1 (diff) |
Merge branch 'rename-packet-to-message' into libradsec-user-dispatch
Conflicts:
lib/include/radsec/radsec.h
Original commit message (1e3a2613):
Rename most 'package' to 'message'.
RADIUS (RFC2865) is defined to be transported over UDP so the term
"radius packet" makes a lot of sense. RADIUS/TCP (RFC6613) and
RADIUS/TLS (RFC6614), a.k.a. RadSec, use stream transport protocols
though. The term "message" doesn't imply any kind of transport -- a
message can be sent using datagrams as well as in a stream.
This (large) commit changes 'package' to 'message' where it makes
sense. It does not touch the 'radius' subdirectory. It includes
preprocessor directives (#define) to make the public interface
compatible with previous releases of the library.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CHANGES | 10 | ||||
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/conn.c | 58 | ||||
-rw-r--r-- | lib/debug.c | 6 | ||||
-rw-r--r-- | lib/debug.h | 4 | ||||
-rw-r--r-- | lib/err.c | 2 | ||||
-rw-r--r-- | lib/event.c | 8 | ||||
-rw-r--r-- | lib/event.h | 2 | ||||
-rw-r--r-- | lib/examples/client-blocking.c | 18 | ||||
-rw-r--r-- | lib/include/radsec/radsec-impl.h | 14 | ||||
-rw-r--r-- | lib/include/radsec/radsec.h | 116 | ||||
-rw-r--r-- | lib/include/radsec/request-impl.h | 2 | ||||
-rw-r--r-- | lib/include/radsec/request.h | 15 | ||||
-rw-r--r-- | lib/message.c (renamed from lib/packet.c) | 134 | ||||
-rw-r--r-- | lib/message.h | 7 | ||||
-rw-r--r-- | lib/packet.h | 7 | ||||
-rw-r--r-- | lib/radsec.sym | 18 | ||||
-rw-r--r-- | lib/request.c | 18 | ||||
-rw-r--r-- | lib/send.c | 38 | ||||
-rw-r--r-- | lib/tcp.c | 130 | ||||
-rw-r--r-- | lib/udp.c | 88 | ||||
-rw-r--r-- | lib/udp.h | 2 |
22 files changed, 360 insertions, 339 deletions
diff --git a/lib/CHANGES b/lib/CHANGES index d293cba..135fd4b 100644 --- a/lib/CHANGES +++ b/lib/CHANGES @@ -1,6 +1,8 @@ Changes in version 0.0.3 - 2013-??-?? - libradsec 0.0.3 <verb> <other words, forming a summary> + libradsec 0.0.3 <summary goes here> - [o Incompatible changes:] - [o Features:] - [o Bug fixes:] + o Compatible internal code changes: + - Most places that used to say 'packet' now say 'message', + including public API:s. Preprocessor directives (#define) are in + place to make the public interface compatible with previous + releases. diff --git a/lib/Makefile.am b/lib/Makefile.am index 46f573a..af4ae4c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -32,7 +32,7 @@ libradsec_la_SOURCES = \ debug.c \ err.c \ event.c \ - packet.c \ + message.c \ peer.c \ radsec.c \ request.c \ @@ -16,7 +16,7 @@ #include "debug.h" #include "conn.h" #include "event.h" -#include "packet.h" +#include "message.h" #include "tcp.h" int @@ -217,85 +217,85 @@ int rs_conn_get_fd (struct rs_connection *conn) } static void -_rcb (struct rs_packet *packet, void *user_data) +_rcb (struct rs_message *message, void *user_data) { - struct rs_packet *pkt = (struct rs_packet *) user_data; - assert (pkt); - assert (pkt->conn); + struct rs_message *msg = (struct rs_message *) user_data; + assert (msg); + assert (msg->conn); - pkt->flags |= RS_PACKET_RECEIVED; - if (pkt->conn->bev) - bufferevent_disable (pkt->conn->bev, EV_WRITE|EV_READ); + msg->flags |= RS_MESSAGE_RECEIVED; + if (msg->conn->bev) + bufferevent_disable (msg->conn->bev, EV_WRITE|EV_READ); else - event_del (pkt->conn->rev); + event_del (msg->conn->rev); } int -rs_conn_receive_packet (struct rs_connection *conn, - struct rs_packet *req_msg, - struct rs_packet **pkt_out) +rs_conn_receive_message (struct rs_connection *conn, + struct rs_message *req_msg, + struct rs_message **msg_out) { int err = 0; - struct rs_packet *pkt = NULL; + struct rs_message *msg = NULL; assert (conn); assert (conn->realm); assert (!conn_user_dispatch_p (conn)); /* Blocking mode only. */ - if (rs_packet_create (conn, &pkt)) + if (rs_message_create (conn, &msg)) return -1; assert (conn->evb); assert (conn->fd >= 0); conn->callbacks.received_cb = _rcb; - conn->user_data = pkt; - pkt->flags &= ~RS_PACKET_RECEIVED; + conn->user_data = msg; + msg->flags &= ~RS_MESSAGE_RECEIVED; if (conn->bev) /* TCP. */ { bufferevent_setwatermark (conn->bev, EV_READ, RS_HEADER_LEN, 0); - bufferevent_setcb (conn->bev, tcp_read_cb, NULL, tcp_event_cb, pkt); + bufferevent_setcb (conn->bev, tcp_read_cb, NULL, tcp_event_cb, msg); bufferevent_enable (conn->bev, EV_READ); } else /* UDP. */ { - /* Put fresh packet in user_data for the callback and enable the + /* Put fresh message in user_data for the callback and enable the read event. */ event_assign (conn->rev, conn->evb, event_get_fd (conn->rev), - EV_READ, event_get_callback (conn->rev), pkt); + EV_READ, event_get_callback (conn->rev), msg); err = event_add (conn->rev, NULL); if (err < 0) - return rs_err_conn_push_fl (pkt->conn, RSE_EVENT, __FILE__, __LINE__, + return rs_err_conn_push_fl (msg->conn, RSE_EVENT, __FILE__, __LINE__, "event_add: %s", evutil_gai_strerror (err)); /* Activate retransmission timer. */ - conn_activate_timeout (pkt->conn); + conn_activate_timeout (msg->conn); } rs_debug (("%s: entering event loop\n", __func__)); err = event_base_dispatch (conn->evb); conn->callbacks.received_cb = NULL; if (err < 0) - return rs_err_conn_push_fl (pkt->conn, RSE_EVENT, __FILE__, __LINE__, + return rs_err_conn_push_fl (msg->conn, RSE_EVENT, __FILE__, __LINE__, "event_base_dispatch: %s", evutil_gai_strerror (err)); rs_debug (("%s: event loop done\n", __func__)); - if ((pkt->flags & RS_PACKET_RECEIVED) == 0 + if ((msg->flags & RS_MESSAGE_RECEIVED) == 0 || (req_msg - && packet_verify_response (pkt->conn, pkt, req_msg) != RSE_OK)) + && message_verify_response (msg->conn, msg, req_msg) != RSE_OK)) { - if (rs_err_conn_peek_code (pkt->conn) == RSE_OK) - /* No packet and no error on the stack _should_ mean that the + if (rs_err_conn_peek_code (msg->conn) == RSE_OK) + /* No message and no error on the stack _should_ mean that the server hung up on us. */ - rs_err_conn_push (pkt->conn, RSE_DISCO, "no response"); + rs_err_conn_push (msg->conn, RSE_DISCO, "no response"); return rs_err_conn_peek_code (conn); } - if (pkt_out) - *pkt_out = pkt; + if (msg_out) + *msg_out = msg; return RSE_OK; } diff --git a/lib/debug.c b/lib/debug.c index 25c7fd6..4d30846 100644 --- a/lib/debug.c +++ b/lib/debug.c @@ -14,13 +14,13 @@ #include "debug.h" void -rs_dump_packet (const struct rs_packet *pkt) +rs_dump_message (const struct rs_message *msg) { const RADIUS_PACKET *p = NULL; - if (!pkt || !pkt->rpkt) + if (!msg || !msg->rpkt) return; - p = pkt->rpkt; + p = msg->rpkt; fprintf (stderr, "\tCode: %u, Identifier: %u, Lenght: %zu\n", p->code, diff --git a/lib/debug.h b/lib/debug.h index c319085..7befa7e 100644 --- a/lib/debug.h +++ b/lib/debug.h @@ -12,8 +12,8 @@ extern "C" { #endif -struct rs_packet; -void rs_dump_packet (const struct rs_packet *pkt); +struct rs_message; +void rs_dump_message (const struct rs_message *pkt); int _rs_debug (const char *fmt, ...); #if defined (DEBUG) @@ -28,7 +28,7 @@ static const char *_errtxt[] = { "authentication failed", /* 12 RSE_BADAUTH */ "internal error", /* 13 RSE_INTERNAL */ "SSL error", /* 14 RSE_SSLERR */ - "invalid packet", /* 15 RSE_INVALID_PKT */ + "invalid message", /* 15 RSE_INVALID_MSG */ "connect timeout", /* 16 RSE_TIMEOUT_CONN */ "invalid argument", /* 17 RSE_INVAL */ "I/O timeout", /* 18 RSE_TIMEOUT_IO */ diff --git a/lib/event.c b/lib/event.c index 3ebc5a7..f768273 100644 --- a/lib/event.c +++ b/lib/event.c @@ -25,7 +25,7 @@ #include "err.h" #include "radsec.h" #include "event.h" -#include "packet.h" +#include "message.h" #include "conn.h" #include "debug.h" @@ -241,7 +241,7 @@ event_on_disconnect (struct rs_connection *conn) /** Internal connect event returning 0 on success or -1 on error. */ int -event_on_connect (struct rs_connection *conn, struct rs_packet *pkt) +event_on_connect (struct rs_connection *conn, struct rs_message *msg) { assert (!conn->is_connecting); @@ -261,8 +261,8 @@ event_on_connect (struct rs_connection *conn, struct rs_packet *pkt) if (conn->callbacks.connected_cb) conn->callbacks.connected_cb (conn->user_data); - if (pkt) - packet_do_send (pkt); + if (msg) + message_do_send (msg); return 0; } diff --git a/lib/event.h b/lib/event.h index 9c239df..3fcea61 100644 --- a/lib/event.h +++ b/lib/event.h @@ -2,7 +2,7 @@ See LICENSE for licensing information. */ void event_on_disconnect (struct rs_connection *conn); -int event_on_connect (struct rs_connection *conn, struct rs_packet *pkt); +int event_on_connect (struct rs_connection *conn, struct rs_message *msg); int event_loopbreak (struct rs_connection *conn); int event_init_eventbase (struct rs_connection *conn); int event_init_socket (struct rs_connection *conn, struct rs_peer *p); diff --git a/lib/examples/client-blocking.c b/lib/examples/client-blocking.c index 1303905..3ea4b51 100644 --- a/lib/examples/client-blocking.c +++ b/lib/examples/client-blocking.c @@ -6,7 +6,7 @@ #include <radsec/radsec.h> #include <radsec/request.h> #include "err.h" -#include "debug.h" /* For rs_dump_packet(). */ +#include "debug.h" /* For rs_dump_message(). */ #define SECRET "sikrit" #define USER_NAME "molgan@PROJECT-MOONSHOT.ORG" @@ -19,7 +19,7 @@ blocking_client (const char *config_fn, const char *configuration, struct rs_context *h = NULL; struct rs_connection *conn = NULL; struct rs_request *request = NULL; - struct rs_packet *req = NULL, *resp = NULL; + struct rs_message *req = NULL, *resp = NULL; struct rs_error *err = NULL; int r; @@ -62,21 +62,21 @@ blocking_client (const char *config_fn, const char *configuration, } else { - if (rs_packet_create_authn_request (conn, &req, USER_NAME, USER_PW, SECRET)) + if (rs_message_create_authn_request (conn, &req, USER_NAME, USER_PW, SECRET)) goto cleanup; - if (rs_packet_send (req, NULL)) + if (rs_message_send (req, NULL)) goto cleanup; - if (rs_conn_receive_packet (conn, req, &resp)) + if (rs_conn_receive_message (conn, req, &resp)) goto cleanup; } if (resp) { - rs_dump_packet (resp); - if (rs_packet_code (resp) == PW_ACCESS_ACCEPT) + rs_dump_message (resp); + if (rs_message_code (resp) == PW_ACCESS_ACCEPT) printf ("Good auth.\n"); else - printf ("Bad auth: %d\n", rs_packet_code (resp)); + printf ("Bad auth: %d\n", rs_message_code (resp)); } else fprintf (stderr, "%s: no response\n", __func__); @@ -86,7 +86,7 @@ blocking_client (const char *config_fn, const char *configuration, if (err == RSE_OK) err = rs_err_conn_pop (conn); if (resp) - rs_packet_destroy (resp); + rs_message_destroy (resp); if (request) rs_request_destroy (request); if (conn) diff --git a/lib/include/radsec/radsec-impl.h b/lib/include/radsec/radsec-impl.h index 6c02dcf..9f8ebbb 100644 --- a/lib/include/radsec/radsec-impl.h +++ b/lib/include/radsec/radsec-impl.h @@ -107,7 +107,7 @@ struct rs_connection { /* UDP transport specifics. */ struct event *wev; /* Write event (for UDP). */ struct event *rev; /* Read event (for UDP). */ - struct rs_packet *out_queue; /* Queue for outgoing UDP packets. */ + struct rs_message *out_queue; /* Queue for outgoing UDP packets. */ #if defined(RS_ENABLE_TLS) /* TLS specifics. */ SSL_CTX *tls_ctx; @@ -115,20 +115,20 @@ struct rs_connection { #endif }; -enum rs_packet_flags { - RS_PACKET_HEADER_READ, - RS_PACKET_RECEIVED, - RS_PACKET_SENT, +enum rs_message_flags { + RS_MESSAGE_HEADER_READ, + RS_MESSAGE_RECEIVED, + RS_MESSAGE_SENT, }; struct radius_packet; -struct rs_packet { +struct rs_message { struct rs_connection *conn; unsigned int flags; uint8_t hdr[RS_HEADER_LEN]; struct radius_packet *rpkt; /* FreeRADIUS object. */ - struct rs_packet *next; /* Used for UDP output queue. */ + struct rs_message *next; /* Used for UDP output queue. */ }; #if defined (__cplusplus) diff --git a/lib/include/radsec/radsec.h b/lib/include/radsec/radsec.h index e54a8e3..ee8c6a8 100644 --- a/lib/include/radsec/radsec.h +++ b/lib/include/radsec/radsec.h @@ -38,7 +38,7 @@ enum rs_error_code { RSE_BADAUTH = 12, RSE_INTERNAL = 13, RSE_SSLERR = 14, /* OpenSSL error. */ - RSE_INVALID_PKT = 15, + RSE_INVALID_MSG = 15, RSE_TIMEOUT_CONN = 16, /* Connection timeout. */ RSE_INVAL = 17, /* Invalid argument. */ RSE_TIMEOUT_IO = 18, /* I/O timeout. */ @@ -118,10 +118,25 @@ typedef enum rs_attr_type_t { extern "C" { #endif +/* Backwards compatible with 0.0.2. */ +#define RSE_INVALID_PKT RSE_INVALID_MSG +#define rs_packet rs_message +#define rs_conn_packet_received_cb rs_conn_message_received_cb +#define rs_conn_packet_sent_cb rs_conn_message_sent_cb +#define rs_conn_receive_packet rs_conn_receive_message +#define rs_dump_packet rs_dump_message +#define rs_packet_append_avp rs_message_append_avp +#define rs_packet_avps rs_message_avps +#define rs_packet_code rs_message_code +#define rs_packet_create rs_message_create +#define rs_packet_create_authn_request rs_message_create_authn_request +#define rs_packet_destroy rs_message_destroy +#define rs_packet_send rs_message_send + /* Data types. */ struct rs_context; /* radsec-impl.h */ struct rs_connection; /* radsec-impl.h */ -struct rs_packet; /* radsec-impl.h */ +struct rs_message; /* radsec-impl.h */ struct rs_conn; /* radsec-impl.h */ struct rs_error; /* radsec-impl.h */ struct rs_peer; /* radsec-impl.h */ @@ -142,18 +157,18 @@ struct rs_alloc_scheme { typedef void (*rs_conn_connected_cb) (void *user_data /* FIXME: peer? */ ); typedef void (*rs_conn_disconnected_cb) (void *user_data /* FIXME: reason? */ ); -typedef void (*rs_conn_packet_received_cb) (struct rs_packet *packet, - void *user_data); -typedef void (*rs_conn_packet_sent_cb) (void *user_data); +typedef void (*rs_conn_message_received_cb) (struct rs_message *message, + void *user_data); +typedef void (*rs_conn_message_sent_cb) (void *user_data); struct rs_conn_callbacks { /** Callback invoked when the connection has been established. */ rs_conn_connected_cb connected_cb; /** Callback invoked when the connection has been torn down. */ rs_conn_disconnected_cb disconnected_cb; - /** Callback invoked when a packet was received. */ - rs_conn_packet_received_cb received_cb; - /** Callback invoked when a packet was successfully sent. */ - rs_conn_packet_sent_cb sent_cb; + /** Callback invoked when a message was received. */ + rs_conn_message_received_cb received_cb; + /** Callback invoked when a message was successfully sent. */ + rs_conn_message_sent_cb sent_cb; }; typedef struct value_pair rs_avp; @@ -199,9 +214,9 @@ int rs_context_read_config(struct rs_context *ctx, const char *config_file); /** Create a connection. \a conn is the address of a pointer to an \a rs_connection, the output. Free the connection using \a rs_conn_destroy. Note that a connection must not be freed before - all packets associated with the connection have been freed. A - packet is associated with a connection when it's created (\a - rs_packet_create) or received (\a rs_conn_receive_packet). + all messages associated with the connection have been freed. A + message is associated with a connection when it's created + (\a rs_message_create) or received (\a rs_conn_receive_message). If \a config is not NULL it should be the name of a realm found in a config file that has already been read using \a rs_context_read_config. @@ -224,10 +239,10 @@ int rs_conn_add_listener(struct rs_connection *conn, int rs_conn_disconnect (struct rs_connection *conn); /** Disconnect and free memory allocated for connection \a conn. Note - that a connection must not be freed before all packets associated - with the connection have been freed. A packet is associated with - a connection when it's created (\a rs_packet_create) or received - (\a rs_conn_receive_packet). \return RSE_OK (0) on success, !0 * + that a connection must not be freed before all messages associated + with the connection have been freed. A message is associated with + a connection when it's created (\a rs_message_create) or received + (\a rs_conn_receive_message). \return RSE_OK (0) on success, !0 * on error. On error, errno is set appropriately. */ int rs_conn_destroy(struct rs_connection *conn); @@ -262,15 +277,15 @@ int rs_conn_get_current_peer(struct rs_connection *conn, If \a req_msg is not NULL, a successfully received RADIUS message is verified against it. If \a pkt_out is not NULL it will upon - return contain a pointer to an \a rs_packet containing the new + return contain a pointer to an \a rs_message containing the new message. \return On error or if the connect (TCP only) or read times out, \a pkt_out will not be changed and one or more errors are pushed on \a conn (available through \a rs_err_conn_pop). */ -int rs_conn_receive_packet(struct rs_connection *conn, - struct rs_packet *request, - struct rs_packet **pkt_out); +int rs_conn_receive_message(struct rs_connection *conn, + struct rs_message *request, + struct rs_message **pkt_out); /** Run the dispatcher for the event base associated with \a conn. A * wrapper around event_base_dispatch() for not having to hand out the @@ -301,58 +316,59 @@ void rs_peer_set_timeout(struct rs_peer *peer, int timeout); void rs_peer_set_retries(struct rs_peer *peer, int retries); /************/ -/* Packet. */ +/* Message. */ /************/ -/** Create a packet associated with connection \a conn. */ -int rs_packet_create(struct rs_connection *conn, struct rs_packet **pkt_out); +/** Create a message associated with connection \a conn. */ +int rs_message_create(struct rs_connection *conn, struct rs_message **pkt_out); -/** Free all memory allocated for packet \a pkt. */ -void rs_packet_destroy(struct rs_packet *pkt); +/** Free all memory allocated for message \a msg. */ +void rs_message_destroy(struct rs_message *msg); -/** Send packet \a pkt on the connection associated with \a pkt. \a - user_data is sent to the \a rs_conn_packet_received_cb callback - registered with the connection. If no callback is registered with - the connection, the event loop is run by \a rs_packet_send and it - blocks until the packet has been succesfully sent. +/** Send message \a msg on the connection associated with \a msg. + \a user_data is sent to the \a rs_conn_message_received_cb callback + registered with the connection. If no callback is registered with + the connection, the event loop is run by \a rs_message_send and it + blocks until the message has been succesfully sent. \return On success, RSE_OK (0) is returned. On error, !0 is returned and a struct \a rs_error is pushed on the error stack for the connection. The error can be accessed using \a rs_err_conn_pop. */ -int rs_packet_send(struct rs_packet *pkt, void *user_data); +int rs_message_send(struct rs_message *msg, void *user_data); -/** Create a RADIUS authentication request packet associated with +/** Create a RADIUS authentication request message associated with connection \a conn. Optionally, User-Name and User-Password - attributes are added to the packet using the data in \a user_name, + attributes are added to the message using the data in \a user_name, \a user_pw and \a secret where \secret is the RADIUS shared secret. */ -int rs_packet_create_authn_request(struct rs_connection *conn, - struct rs_packet **pkt, - const char *user_name, - const char *user_pw, - const char *secret); +int rs_message_create_authn_request(struct rs_connection *conn, + struct rs_message **msg, + const char *user_name, + const char *user_pw, + const char *secret); -/*** Append \a tail to packet \a pkt. */ +/*** Append \a tail to message \a msg. */ int -rs_packet_append_avp(struct rs_packet *pkt, - unsigned int attribute, unsigned int vendor, - const void *data, size_t data_len); +rs_message_append_avp(struct rs_message *msg, + unsigned int attribute, unsigned int vendor, + const void *data, size_t data_len); -/*** Get pointer to \a pkt attribute value pairs. */ +/*** Get pointer to \a msg attribute value pairs. */ void -rs_packet_avps(struct rs_packet *pkt, rs_avp ***vps); +rs_message_avps(struct rs_message *msg, rs_avp ***vps); -/*** Get RADIUS packet type of \a pkt. */ +/*** Get RADIUS message type of \a msg. */ unsigned int -rs_packet_code(struct rs_packet *pkt); +rs_message_code(struct rs_message *msg); -/*** Get RADIUS AVP from \a pkt. */ +/*** Get RADIUS AVP from \a msg. */ rs_const_avp * -rs_packet_find_avp(struct rs_packet *pkt, unsigned int attr, unsigned int vendor); +rs_message_find_avp(struct rs_message *msg, unsigned int attr, + unsigned int vendor); -/*** Set packet identifier in \a pkt; returns old identifier */ +/*** Set packet identifier in \a msg; returns old identifier */ int -rs_packet_set_id (struct rs_packet *pkt, int id); +rs_message_set_id (struct rs_message *msg, int id); /************/ /* Config. */ diff --git a/lib/include/radsec/request-impl.h b/lib/include/radsec/request-impl.h index bb61dd6..9af1394 100644 --- a/lib/include/radsec/request-impl.h +++ b/lib/include/radsec/request-impl.h @@ -11,7 +11,7 @@ struct rs_request { struct rs_connection *conn; struct event *timer; - struct rs_packet *req_msg; + struct rs_message *req_msg; struct rs_conn_callbacks saved_cb; void *saved_user_data; }; diff --git a/lib/include/radsec/request.h b/lib/include/radsec/request.h index f0151f8..05b5daa 100644 --- a/lib/include/radsec/request.h +++ b/lib/include/radsec/request.h @@ -6,6 +6,10 @@ #ifndef _RADSEC_REQUEST_H_ #define _RADSEC_REQUEST_H_ 1 +/* Backwards compatible with 0.0.2. */ +#define rs_request_add_reqpkt rs_request_add_reqmsg +#define rs_request_get_reqpkt rs_request_get_reqmsg + struct rs_request; #if defined (__cplusplus) @@ -15,9 +19,8 @@ extern "C" { /** Create a request associated with connection \a conn. */ int rs_request_create(struct rs_connection *conn, struct rs_request **req_out); -/** Add RADIUS request message \a req_msg to request \a req. - FIXME: Rename to rs_request_add_reqmsg? */ -void rs_request_add_reqpkt(struct rs_request *req, struct rs_packet *req_msg); +/** Add RADIUS request message \a req_msg to request \a req. */ +void rs_request_add_reqmsg(struct rs_request *req, struct rs_message *req_msg); /** Create a request associated with connection \a conn containing a newly created RADIUS authentication message, possibly with @@ -35,15 +38,15 @@ int rs_request_create_authn(struct rs_connection *conn, response is put in \a resp_msg (if not NULL). NOTE: At present, no more than one outstanding request to a given realm is supported. This will change in a future version. */ -int rs_request_send(struct rs_request *req, struct rs_packet **resp_msg); +int rs_request_send(struct rs_request *req, struct rs_message **resp_msg); /** Free all memory allocated by request \a req including any request - packet associated with the request. Note that a request must be + message associated with the request. Note that a request must be freed before its associated connection can be freed. */ void rs_request_destroy(struct rs_request *req); /** Return request message in request \a req. */ -struct rs_packet *rs_request_get_reqmsg(const struct rs_request *req); +struct rs_message *rs_request_get_reqmsg(const struct rs_request *req); #if defined (__cplusplus) } diff --git a/lib/packet.c b/lib/message.c index 17f022e..bdefed3 100644 --- a/lib/packet.c +++ b/lib/message.c @@ -12,7 +12,7 @@ #include <radsec/radsec-impl.h> #include "conn.h" #include "debug.h" -#include "packet.h" +#include "message.h" #if defined (DEBUG) #include <netdb.h> @@ -21,9 +21,9 @@ #endif int -packet_verify_response (struct rs_connection *conn, - struct rs_packet *response, - struct rs_packet *request) +message_verify_response (struct rs_connection *conn, + struct rs_message *response, + struct rs_message *request) { int err; @@ -65,59 +65,59 @@ packet_verify_response (struct rs_connection *conn, /* Badly named function for preparing a RADIUS message and queue it. FIXME: Rename. */ int -packet_do_send (struct rs_packet *pkt) +message_do_send (struct rs_message *msg) { int err; - assert (pkt); - assert (pkt->conn); - assert (pkt->conn->active_peer); - assert (pkt->conn->active_peer->secret); - assert (pkt->rpkt); + assert (msg); + assert (msg->conn); + assert (msg->conn->active_peer); + assert (msg->conn->active_peer->secret); + assert (msg->rpkt); - pkt->rpkt->secret = pkt->conn->active_peer->secret; - pkt->rpkt->sizeof_secret = strlen (pkt->rpkt->secret); + msg->rpkt->secret = msg->conn->active_peer->secret; + msg->rpkt->sizeof_secret = strlen (msg->rpkt->secret); /* Encode message. */ - err = nr_packet_encode (pkt->rpkt, NULL); + err = nr_packet_encode (msg->rpkt, NULL); if (err < 0) - return rs_err_conn_push_fl (pkt->conn, -err, __FILE__, __LINE__, + return rs_err_conn_push_fl (msg->conn, -err, __FILE__, __LINE__, "nr_packet_encode"); /* Sign message. */ - err = nr_packet_sign (pkt->rpkt, NULL); + err = nr_packet_sign (msg->rpkt, NULL); if (err < 0) - return rs_err_conn_push_fl (pkt->conn, -err, __FILE__, __LINE__, + return rs_err_conn_push_fl (msg->conn, -err, __FILE__, __LINE__, "nr_packet_sign"); #if defined (DEBUG) { char host[80], serv[80]; - getnameinfo (pkt->conn->active_peer->addr_cache->ai_addr, - pkt->conn->active_peer->addr_cache->ai_addrlen, + getnameinfo (msg->conn->active_peer->addr_cache->ai_addr, + msg->conn->active_peer->addr_cache->ai_addrlen, host, sizeof(host), serv, sizeof(serv), 0 /* NI_NUMERICHOST|NI_NUMERICSERV*/); rs_debug (("%s: about to send this to %s:%s:\n", __func__, host, serv)); - rs_dump_packet (pkt); + rs_dump_message (msg); } #endif /* Put message in output buffer. */ - if (pkt->conn->bev) /* TCP. */ + if (msg->conn->bev) /* TCP. */ { - int err = bufferevent_write (pkt->conn->bev, pkt->rpkt->data, - pkt->rpkt->length); + int err = bufferevent_write (msg->conn->bev, msg->rpkt->data, + msg->rpkt->length); if (err < 0) - return rs_err_conn_push_fl (pkt->conn, RSE_EVENT, __FILE__, __LINE__, + return rs_err_conn_push_fl (msg->conn, RSE_EVENT, __FILE__, __LINE__, "bufferevent_write: %s", evutil_gai_strerror (err)); } else /* UDP. */ { - struct rs_packet **pp = &pkt->conn->out_queue; + struct rs_message **pp = &msg->conn->out_queue; while (*pp && (*pp)->next) *pp = (*pp)->next; - *pp = pkt; + *pp = msg; } return RSE_OK; @@ -125,13 +125,13 @@ packet_do_send (struct rs_packet *pkt) /* Public functions. */ int -rs_packet_create (struct rs_connection *conn, struct rs_packet **pkt_out) +rs_message_create (struct rs_connection *conn, struct rs_message **msg_out) { - struct rs_packet *p; + struct rs_message *p; RADIUS_PACKET *rpkt; int err; - *pkt_out = NULL; + *msg_out = NULL; rpkt = rs_malloc (conn->ctx, sizeof(*rpkt) + RS_MAX_PACKET_LEN); if (rpkt == NULL) @@ -153,7 +153,7 @@ rs_packet_create (struct rs_connection *conn, struct rs_packet **pkt_out) if (err < 0) return rs_err_conn_push (conn, -err, __func__); - p = (struct rs_packet *) rs_calloc (conn->ctx, 1, sizeof (*p)); + p = (struct rs_message *) rs_calloc (conn->ctx, 1, sizeof (*p)); if (p == NULL) { rs_free (conn->ctx, rpkt); @@ -162,37 +162,37 @@ rs_packet_create (struct rs_connection *conn, struct rs_packet **pkt_out) p->conn = conn; p->rpkt = rpkt; - *pkt_out = p; + *msg_out = p; return RSE_OK; } int -rs_packet_create_authn_request (struct rs_connection *conn, - struct rs_packet **pkt_out, - const char *user_name, - const char *user_pw, - const char *secret) +rs_message_create_authn_request (struct rs_connection *conn, + struct rs_message **msg_out, + const char *user_name, + const char *user_pw, + const char *secret) { - struct rs_packet *pkt; + struct rs_message *msg; int err; - if (rs_packet_create (conn, pkt_out)) + if (rs_message_create (conn, msg_out)) return -1; - pkt = *pkt_out; - pkt->rpkt->code = PW_ACCESS_REQUEST; + msg = *msg_out; + msg->rpkt->code = PW_ACCESS_REQUEST; if (user_name) { - err = rs_packet_append_avp (pkt, PW_USER_NAME, 0, user_name, 0); + err = rs_message_append_avp (msg, PW_USER_NAME, 0, user_name, 0); if (err) return err; } if (user_pw) { - pkt->rpkt->secret = secret; - err = rs_packet_append_avp (pkt, PW_USER_PASSWORD, 0, user_pw, 0); + msg->rpkt->secret = secret; + err = rs_message_append_avp (msg, PW_USER_PASSWORD, 0, user_pw, 0); if (err) return err; } @@ -201,65 +201,65 @@ rs_packet_create_authn_request (struct rs_connection *conn, } void -rs_packet_destroy (struct rs_packet *pkt) +rs_message_destroy (struct rs_message *msg) { - assert (pkt); - assert (pkt->conn); - assert (pkt->conn->ctx); + assert (msg); + assert (msg->conn); + assert (msg->conn->ctx); - rs_avp_free (&pkt->rpkt->vps); - rs_free (pkt->conn->ctx, pkt->rpkt); - rs_free (pkt->conn->ctx, pkt); + rs_avp_free (&msg->rpkt->vps); + rs_free (msg->conn->ctx, msg->rpkt); + rs_free (msg->conn->ctx, msg); } int -rs_packet_append_avp (struct rs_packet *pkt, - unsigned int attr, unsigned int vendor, - const void *data, size_t data_len) +rs_message_append_avp (struct rs_message *msg, + unsigned int attr, unsigned int vendor, + const void *data, size_t data_len) { const DICT_ATTR *da; int err; - assert (pkt); + assert (msg); da = nr_dict_attr_byvalue (attr, vendor); if (da == NULL) return RSE_ATTR_TYPE_UNKNOWN; - err = nr_packet_attr_append (pkt->rpkt, NULL, da, data, data_len); + err = nr_packet_attr_append (msg->rpkt, NULL, da, data, data_len); if (err < 0) - return rs_err_conn_push (pkt->conn, -err, __func__); + return rs_err_conn_push (msg->conn, -err, __func__); return RSE_OK; } void -rs_packet_avps (struct rs_packet *pkt, rs_avp ***vps) +rs_message_avps (struct rs_message *msg, rs_avp ***vps) { - assert (pkt); - *vps = &pkt->rpkt->vps; + assert (msg); + *vps = &msg->rpkt->vps; } unsigned int -rs_packet_code (struct rs_packet *pkt) +rs_message_code (struct rs_message *msg) { - assert (pkt); - return pkt->rpkt->code; + assert (msg); + return msg->rpkt->code; } rs_const_avp * -rs_packet_find_avp (struct rs_packet *pkt, unsigned int attr, unsigned int vendor) +rs_message_find_avp (struct rs_message *msg, unsigned int attr, unsigned int vendor) { - assert (pkt); - return rs_avp_find_const (pkt->rpkt->vps, attr, vendor); + assert (msg); + return rs_avp_find_const (msg->rpkt->vps, attr, vendor); } int -rs_packet_set_id (struct rs_packet *pkt, int id) +rs_message_set_id (struct rs_message *msg, int id) { - int old = pkt->rpkt->id; + int old = msg->rpkt->id; - pkt->rpkt->id = id; + msg->rpkt->id = id; return old; } diff --git a/lib/message.h b/lib/message.h new file mode 100644 index 0000000..82f2653 --- /dev/null +++ b/lib/message.h @@ -0,0 +1,7 @@ +/* Copyright 2010, 2011 NORDUnet A/S. All rights reserved. + See LICENSE for licensing information. */ + +int message_do_send (struct rs_message *msg); +int message_verify_response (struct rs_connection *conn, + struct rs_message *response, + struct rs_message *request); diff --git a/lib/packet.h b/lib/packet.h deleted file mode 100644 index c020d69..0000000 --- a/lib/packet.h +++ /dev/null @@ -1,7 +0,0 @@ -/* Copyright 2010, 2011 NORDUnet A/S. All rights reserved. - See LICENSE for licensing information. */ - -int packet_do_send (struct rs_packet *pkt); -int packet_verify_response (struct rs_connection *conn, - struct rs_packet *response, - struct rs_packet *request); diff --git a/lib/radsec.sym b/lib/radsec.sym index 9158c20..11f2468 100644 --- a/lib/radsec.sym +++ b/lib/radsec.sym @@ -45,7 +45,7 @@ rs_conn_dispatch rs_conn_fd rs_conn_get_callbacks rs_conn_get_current_peer -rs_conn_receive_packet +rs_conn_receive_message rs_conn_select_peer rs_conn_set_callbacks rs_conn_set_eventbase @@ -55,7 +55,7 @@ rs_context_create rs_context_destroy rs_context_read_config rs_context_set_alloc_scheme -rs_dump_packet +rs_dump_message rs_err_code rs_err_conn_peek_code rs_err_conn_pop @@ -66,13 +66,13 @@ rs_err_ctx_push rs_err_ctx_push_fl rs_err_free rs_err_msg -rs_packet_append_avp -rs_packet_avps -rs_packet_code -rs_packet_create -rs_packet_create_authn_request -rs_packet_destroy -rs_packet_send +rs_message_append_avp +rs_message_avps +rs_message_code +rs_message_create +rs_message_create_authn_request +rs_message_destroy +rs_message_send rs_peer_create rs_peer_set_address rs_peer_set_retries diff --git a/lib/request.c b/lib/request.c index 9ad7843..8f3635d 100644 --- a/lib/request.c +++ b/lib/request.c @@ -41,7 +41,7 @@ rs_request_create (struct rs_connection *conn, struct rs_request **req_out) } void -rs_request_add_reqpkt (struct rs_request *req, struct rs_packet *req_msg) +rs_request_add_reqmsg (struct rs_request *req, struct rs_message *req_msg) { assert (req); req->req_msg = req_msg; @@ -60,7 +60,7 @@ rs_request_create_authn (struct rs_connection *conn, if (rs_request_create (conn, &req)) return -1; - if (rs_packet_create_authn_request (conn, &req->req_msg, user_name, user_pw, secret)) + if (rs_message_create_authn_request (conn, &req->req_msg, user_name, user_pw, secret)) return -1; if (req_out) @@ -76,7 +76,7 @@ rs_request_destroy (struct rs_request *request) assert (request->conn->ctx); if (request->req_msg) - rs_packet_destroy (request->req_msg); + rs_message_destroy (request->req_msg); rs_free (request->conn->ctx, request); } @@ -89,7 +89,7 @@ _rand_rt (struct timeval *res, uint32_t rtprev, uint32_t factor) } int -rs_request_send (struct rs_request *request, struct rs_packet **resp_msg) +rs_request_send (struct rs_request *request, struct rs_message **resp_msg) { int r = 0; struct rs_connection *conn = NULL; @@ -112,12 +112,12 @@ rs_request_send (struct rs_request *request, struct rs_packet **resp_msg) { rs_conn_set_timeout (conn, &rt); - r = rs_packet_send (request->req_msg, NULL); + r = rs_message_send (request->req_msg, NULL); if (r == RSE_OK) { - r = rs_conn_receive_packet (request->conn, - request->req_msg, - resp_msg); + r = rs_conn_receive_message (request->conn, + request->req_msg, + resp_msg); if (r == RSE_OK) break; /* Success. */ @@ -149,7 +149,7 @@ rs_request_send (struct rs_request *request, struct rs_packet **resp_msg) return r; } -struct rs_packet * +struct rs_message * rs_request_get_reqmsg (const struct rs_request *request) { assert (request); @@ -11,7 +11,7 @@ #include <radsec/radsec.h> #include <radsec/radsec-impl.h> #include "debug.h" -#include "packet.h" +#include "message.h" #include "event.h" #include "peer.h" #include "conn.h" @@ -19,7 +19,7 @@ #include "udp.h" static int -_conn_open (struct rs_connection *conn, struct rs_packet *pkt) +_conn_open (struct rs_connection *conn, struct rs_message *msg) { if (event_init_eventbase (conn)) return -1; @@ -42,7 +42,7 @@ _conn_open (struct rs_connection *conn, struct rs_packet *pkt) } else { - if (udp_init (conn, pkt)) + if (udp_init (conn, msg)) return -1; if (udp_init_retransmit_timer (conn)) return -1; @@ -65,29 +65,29 @@ _conn_is_open_p (struct rs_connection *conn) static void _wcb (void *user_data) { - struct rs_packet *pkt = (struct rs_packet *) user_data; - assert (pkt); - pkt->flags |= RS_PACKET_SENT; - if (pkt->conn->bev) - bufferevent_disable (pkt->conn->bev, EV_WRITE|EV_READ); + struct rs_message *msg = (struct rs_message *) user_data; + assert (msg); + msg->flags |= RS_MESSAGE_SENT; + if (msg->conn->bev) + bufferevent_disable (msg->conn->bev, EV_WRITE|EV_READ); else - event_del (pkt->conn->wev); + event_del (msg->conn->wev); } int -rs_packet_send (struct rs_packet *pkt, void *user_data) +rs_message_send (struct rs_message *msg, void *user_data) { struct rs_connection *conn = NULL; int err = 0; - assert (pkt); - assert (pkt->conn); - conn = pkt->conn; + assert (msg); + assert (msg->conn); + conn = msg->conn; if (_conn_is_open_p (conn)) - packet_do_send (pkt); + message_do_send (msg); else - if (_conn_open (conn, pkt)) + if (_conn_open (conn, msg)) return -1; assert (conn->evb); @@ -98,13 +98,13 @@ rs_packet_send (struct rs_packet *pkt, void *user_data) if (conn->bev) /* TCP */ { - bufferevent_setcb (conn->bev, NULL, tcp_write_cb, tcp_event_cb, pkt); + bufferevent_setcb (conn->bev, NULL, tcp_write_cb, tcp_event_cb, msg); bufferevent_enable (conn->bev, EV_WRITE); } else /* UDP */ { event_assign (conn->wev, conn->evb, event_get_fd (conn->wev), - EV_WRITE, event_get_callback (conn->wev), pkt); + EV_WRITE, event_get_callback (conn->wev), msg); err = event_add (conn->wev, NULL); if (err < 0) return rs_err_conn_push_fl (conn, RSE_EVENT, __FILE__, __LINE__, @@ -116,7 +116,7 @@ rs_packet_send (struct rs_packet *pkt, void *user_data) if (!conn_user_dispatch_p (conn)) { conn->callbacks.sent_cb = _wcb; - conn->user_data = pkt; + conn->user_data = msg; rs_debug (("%s: entering event loop\n", __func__)); err = event_base_dispatch (conn->evb); if (err < 0) @@ -127,7 +127,7 @@ rs_packet_send (struct rs_packet *pkt, void *user_data) conn->callbacks.sent_cb = NULL; conn->user_data = NULL; - if ((pkt->flags & RS_PACKET_SENT) == 0) + if ((msg->flags & RS_MESSAGE_SENT) == 0) { assert (rs_err_conn_peek_code (conn)); return rs_err_conn_peek_code (conn); @@ -16,7 +16,7 @@ #include <radsec/radsec.h> #include <radsec/radsec-impl.h> #include "tcp.h" -#include "packet.h" +#include "message.h" #include "conn.h" #include "debug.h" #include "event.h" @@ -25,29 +25,29 @@ #include <event2/buffer.h> #endif -/** Read one RADIUS packet header. Return !0 on error. */ +/** Read one RADIUS message header. Return !0 on error. */ static int -_read_header (struct rs_packet *pkt) +_read_header (struct rs_message *msg) { size_t n = 0; - n = bufferevent_read (pkt->conn->bev, pkt->hdr, RS_HEADER_LEN); + n = bufferevent_read (msg->conn->bev, msg->hdr, RS_HEADER_LEN); if (n == RS_HEADER_LEN) { - pkt->flags |= RS_PACKET_HEADER_READ; - pkt->rpkt->length = (pkt->hdr[2] << 8) + pkt->hdr[3]; - if (pkt->rpkt->length < 20 || pkt->rpkt->length > RS_MAX_PACKET_LEN) + msg->flags |= RS_MESSAGE_HEADER_READ; + msg->rpkt->length = (msg->hdr[2] << 8) + msg->hdr[3]; + if (msg->rpkt->length < 20 || msg->rpkt->length > RS_MAX_PACKET_LEN) { - conn_close (&pkt->conn); - return rs_err_conn_push (pkt->conn, RSE_INVALID_PKT, - "invalid packet length: %d", - pkt->rpkt->length); + conn_close (&msg->conn); + return rs_err_conn_push (msg->conn, RSE_INVALID_MSG, + "invalid message length: %d", + msg->rpkt->length); } - memcpy (pkt->rpkt->data, pkt->hdr, RS_HEADER_LEN); - bufferevent_setwatermark (pkt->conn->bev, EV_READ, - pkt->rpkt->length - RS_HEADER_LEN, 0); - rs_debug (("%s: packet header read, total pkt len=%d\n", - __func__, pkt->rpkt->length)); + memcpy (msg->rpkt->data, msg->hdr, RS_HEADER_LEN); + bufferevent_setwatermark (msg->conn->bev, EV_READ, + msg->rpkt->length - RS_HEADER_LEN, 0); + rs_debug (("%s: message header read, total msg len=%d\n", + __func__, msg->rpkt->length)); } else if (n < 0) { @@ -55,8 +55,8 @@ _read_header (struct rs_packet *pkt) } else /* Error: libevent gave us less than the low watermark. */ { - conn_close (&pkt->conn); - return rs_err_conn_push_fl (pkt->conn, RSE_INTERNAL, __FILE__, __LINE__, + conn_close (&msg->conn); + return rs_err_conn_push_fl (msg->conn, RSE_INTERNAL, __FILE__, __LINE__, "got %d octets reading header", n); } @@ -66,66 +66,66 @@ _read_header (struct rs_packet *pkt) /** Read a message, check that it's valid RADIUS and hand it off to registered user callback. - The packet is read from the bufferevent associated with \a pkt and - the data is stored in \a pkt->rpkt. + The message is read from the bufferevent associated with \a msg and + the data is stored in \a msg->rpkt. Return 0 on success and !0 on failure. */ static int -_read_packet (struct rs_packet *pkt) +_read_message (struct rs_message *msg) { size_t n = 0; int err; - rs_debug (("%s: trying to read %d octets of packet data\n", __func__, - pkt->rpkt->length - RS_HEADER_LEN)); + rs_debug (("%s: trying to read %d octets of message data\n", __func__, + msg->rpkt->length - RS_HEADER_LEN)); - n = bufferevent_read (pkt->conn->bev, - pkt->rpkt->data + RS_HEADER_LEN, - pkt->rpkt->length - RS_HEADER_LEN); + n = bufferevent_read (msg->conn->bev, + msg->rpkt->data + RS_HEADER_LEN, + msg->rpkt->length - RS_HEADER_LEN); - rs_debug (("%s: read %ld octets of packet data\n", __func__, n)); + rs_debug (("%s: read %ld octets of message data\n", __func__, n)); - if (n == pkt->rpkt->length - RS_HEADER_LEN) + if (n == msg->rpkt->length - RS_HEADER_LEN) { - bufferevent_disable (pkt->conn->bev, EV_READ); - rs_debug (("%s: complete packet read\n", __func__)); - pkt->flags &= ~RS_PACKET_HEADER_READ; - memset (pkt->hdr, 0, sizeof(*pkt->hdr)); + bufferevent_disable (msg->conn->bev, EV_READ); + rs_debug (("%s: complete message read\n", __func__)); + msg->flags &= ~RS_MESSAGE_HEADER_READ; + memset (msg->hdr, 0, sizeof(*msg->hdr)); - /* Checks done by rad_packet_ok: + /* Checks done by nr_packet_ok: - lenghts (FIXME: checks really ok for tcp?) - invalid code field - attribute lengths >= 2 - attribute sizes adding up correctly */ - err = nr_packet_ok (pkt->rpkt); + err = nr_packet_ok (msg->rpkt); if (err != RSE_OK) { - conn_close (&pkt->conn); - return rs_err_conn_push_fl (pkt->conn, err, __FILE__, __LINE__, - "invalid packet"); + conn_close (&msg->conn); + return rs_err_conn_push_fl (msg->conn, err, __FILE__, __LINE__, + "invalid message"); } #if defined (DEBUG) /* Find out what happens if there's data left in the buffer. */ { size_t rest = 0; - rest = evbuffer_get_length (bufferevent_get_input (pkt->conn->bev)); + rest = evbuffer_get_length (bufferevent_get_input (msg->conn->bev)); if (rest) rs_debug (("%s: returning with %d octets left in buffer\n", __func__, rest)); } #endif - /* Hand over message to user. This changes ownership of pkt. + /* Hand over message to user. This changes ownership of msg. Don't touch it afterwards -- it might have been freed. */ - if (pkt->conn->callbacks.received_cb) - pkt->conn->callbacks.received_cb (pkt, pkt->conn->user_data); + if (msg->conn->callbacks.received_cb) + msg->conn->callbacks.received_cb (msg, msg->conn->user_data); } else if (n < 0) /* Buffer frozen. */ - rs_debug (("%s: buffer frozen when reading packet\n", __func__)); - else /* Short packet. */ + rs_debug (("%s: buffer frozen when reading message\n", __func__)); + else /* Short message. */ rs_debug (("%s: waiting for another %d octets\n", __func__, - pkt->rpkt->length - RS_HEADER_LEN - n)); + msg->rpkt->length - RS_HEADER_LEN - n)); return 0; } @@ -133,21 +133,21 @@ _read_packet (struct rs_packet *pkt) /* The read callback for TCP. Read exactly one RADIUS message from BEV and store it in struct - rs_packet passed in USER_DATA. + rs_message passed in USER_DATA. Inform upper layer about successful reception of received RADIUS message by invoking conn->callbacks.recevied_cb(), if !NULL. */ void tcp_read_cb (struct bufferevent *bev, void *user_data) { - struct rs_packet *pkt = (struct rs_packet *) user_data; + struct rs_message *msg = (struct rs_message *) user_data; - assert (pkt); - assert (pkt->conn); - assert (pkt->rpkt); + assert (msg); + assert (msg->conn); + assert (msg->rpkt); - pkt->rpkt->sockfd = pkt->conn->fd; - pkt->rpkt->vps = NULL; /* FIXME: can this be done when initializing pkt? */ + msg->rpkt->sockfd = msg->conn->fd; + msg->rpkt->vps = NULL; /* FIXME: can this be done when initializing msg? */ /* Read a message header if not already read, return if that fails. Read a message and have it dispatched to the user @@ -155,16 +155,16 @@ tcp_read_cb (struct bufferevent *bev, void *user_data) Room for improvement: Peek inside buffer (evbuffer_copyout()) to avoid the extra copying. */ - if ((pkt->flags & RS_PACKET_HEADER_READ) == 0) - if (_read_header (pkt)) + if ((msg->flags & RS_MESSAGE_HEADER_READ) == 0) + if (_read_header (msg)) return; /* Error. */ - _read_packet (pkt); + _read_message (msg); } void tcp_event_cb (struct bufferevent *bev, short events, void *user_data) { - struct rs_packet *pkt = (struct rs_packet *) user_data; + struct rs_message *msg = (struct rs_message *) user_data; struct rs_connection *conn = NULL; int sockerr = 0; #if defined (RS_ENABLE_TLS) @@ -174,11 +174,11 @@ tcp_event_cb (struct bufferevent *bev, short events, void *user_data) struct rs_peer *p = NULL; #endif - assert (pkt); - assert (pkt->conn); - conn = pkt->conn; + assert (msg); + assert (msg->conn); + conn = msg->conn; #if defined (DEBUG) - assert (pkt->conn->active_peer); + assert (msg->conn->active_peer); p = conn->active_peer; #endif @@ -187,7 +187,7 @@ tcp_event_cb (struct bufferevent *bev, short events, void *user_data) { if (conn->tev) evtimer_del (conn->tev); /* Cancel connect timer. */ - if (event_on_connect (conn, pkt)) + if (event_on_connect (conn, msg)) { event_on_disconnect (conn); event_loopbreak (conn); @@ -245,13 +245,13 @@ tcp_event_cb (struct bufferevent *bev, short events, void *user_data) void tcp_write_cb (struct bufferevent *bev, void *ctx) { - struct rs_packet *pkt = (struct rs_packet *) ctx; + struct rs_message *msg = (struct rs_message *) ctx; - assert (pkt); - assert (pkt->conn); + assert (msg); + assert (msg->conn); - if (pkt->conn->callbacks.sent_cb) - pkt->conn->callbacks.sent_cb (pkt->conn->user_data); + if (msg->conn->callbacks.sent_cb) + msg->conn->callbacks.sent_cb (msg->conn->user_data); } int @@ -22,32 +22,32 @@ static int _send (struct rs_connection *conn, int fd) { ssize_t r = 0; - struct rs_packet *pkt = conn->out_queue; + struct rs_message *msg = conn->out_queue; - assert (pkt->rpkt); - assert (pkt->rpkt->data); + assert (msg->rpkt); + assert (msg->rpkt->data); /* Send. */ - r = compat_send (fd, pkt->rpkt->data, pkt->rpkt->length, 0); + r = compat_send (fd, msg->rpkt->data, msg->rpkt->length, 0); if (r == -1) { - int sockerr = evutil_socket_geterror (pkt->conn->fd); + int sockerr = evutil_socket_geterror (msg->conn->fd); if (sockerr != EAGAIN) - return rs_err_conn_push_fl (pkt->conn, RSE_SOCKERR, __FILE__, __LINE__, + return rs_err_conn_push_fl (msg->conn, RSE_SOCKERR, __FILE__, __LINE__, "%d: send: %d (%s)", fd, sockerr, evutil_socket_error_to_string (sockerr)); } - assert (r == pkt->rpkt->length); - /* Unlink the packet. */ - conn->out_queue = pkt->next; + assert (r == msg->rpkt->length); + /* Unlink the message. */ + conn->out_queue = msg->next; - /* If there are more packets in queue, add the write event again. */ - if (pkt->conn->out_queue) + /* If there are more messages in queue, add the write event again. */ + if (msg->conn->out_queue) { - r = event_add (pkt->conn->wev, NULL); + r = event_add (msg->conn->wev, NULL); if (r < 0) - return rs_err_conn_push_fl (pkt->conn, RSE_EVENT, __FILE__, __LINE__, + return rs_err_conn_push_fl (msg->conn, RSE_EVENT, __FILE__, __LINE__, "event_add: %s", evutil_gai_strerror (r)); rs_debug (("%s: re-adding the write event\n", __func__)); } @@ -57,10 +57,10 @@ _send (struct rs_connection *conn, int fd) /* Callback for conn->wev and conn->rev. FIXME: Rename. - USER_DATA contains connection for EV_READ and a packet for + USER_DATA contains connection for EV_READ and a message for EV_WRITE. This is because we don't have a connect/establish entry point at the user level -- send implies connect so when we're - connected we need the packet to send. */ + connected we need the message to send. */ static void _evcb (evutil_socket_t fd, short what, void *user_data) { @@ -76,17 +76,17 @@ _evcb (evutil_socket_t fd, short what, void *user_data) { /* Read a single UDP packet and stick it in USER_DATA. */ /* TODO: Verify that unsolicited packets are dropped. */ - struct rs_packet *pkt = (struct rs_packet *) user_data; + struct rs_message *msg = (struct rs_message *) user_data; ssize_t r = 0; - assert (pkt); - assert (pkt->conn); - assert (pkt->rpkt->data); + assert (msg); + assert (msg->conn); + assert (msg->rpkt->data); - r = compat_recv (fd, pkt->rpkt->data, RS_MAX_PACKET_LEN, MSG_TRUNC); + r = compat_recv (fd, msg->rpkt->data, RS_MAX_PACKET_LEN, MSG_TRUNC); if (r == -1) { - int sockerr = evutil_socket_geterror (pkt->conn->fd); + int sockerr = evutil_socket_geterror (msg->conn->fd); if (sockerr == EAGAIN) { /* FIXME: Really shouldn't happen since we've been told @@ -96,46 +96,46 @@ _evcb (evutil_socket_t fd, short what, void *user_data) } /* Hard error. */ - rs_err_conn_push_fl (pkt->conn, RSE_SOCKERR, __FILE__, __LINE__, + rs_err_conn_push_fl (msg->conn, RSE_SOCKERR, __FILE__, __LINE__, "%d: recv: %d (%s)", fd, sockerr, evutil_socket_error_to_string (sockerr)); - event_del (pkt->conn->tev); + event_del (msg->conn->tev); return; } - event_del (pkt->conn->tev); + event_del (msg->conn->tev); if (r < 20 || r > RS_MAX_PACKET_LEN) /* Short or long packet. */ { - rs_err_conn_push (pkt->conn, RSE_INVALID_PKT, - "invalid packet length: %d", - pkt->rpkt->length); + rs_err_conn_push (msg->conn, RSE_INVALID_MSG, + "invalid message length: %d", + msg->rpkt->length); return; } - pkt->rpkt->length = (pkt->rpkt->data[2] << 8) + pkt->rpkt->data[3]; - err = nr_packet_ok (pkt->rpkt); + msg->rpkt->length = (msg->rpkt->data[2] << 8) + msg->rpkt->data[3]; + err = nr_packet_ok (msg->rpkt); if (err) { - rs_err_conn_push_fl (pkt->conn, err, __FILE__, __LINE__, - "invalid packet"); + rs_err_conn_push_fl (msg->conn, err, __FILE__, __LINE__, + "invalid message"); return; } - /* Hand over message to user. This changes ownership of pkt. + /* Hand over message to user. This changes ownership of msg. Don't touch it afterwards -- it might have been freed. */ - if (pkt->conn->callbacks.received_cb) - pkt->conn->callbacks.received_cb (pkt, pkt->conn->user_data); + if (msg->conn->callbacks.received_cb) + msg->conn->callbacks.received_cb (msg, msg->conn->user_data); } else if (what & EV_WRITE) { - struct rs_packet *pkt = (struct rs_packet *) user_data; - assert (pkt); - assert (pkt->conn); + struct rs_message *msg = (struct rs_message *) user_data; + assert (msg); + assert (msg->conn); - if (!pkt->conn->is_connected) - event_on_connect (pkt->conn, pkt); + if (!msg->conn->is_connected) + event_on_connect (msg->conn, msg); - if (pkt->conn->out_queue) - if (_send (pkt->conn, fd) == RSE_OK) - if (pkt->conn->callbacks.sent_cb) - pkt->conn->callbacks.sent_cb (pkt->conn->user_data); + if (msg->conn->out_queue) + if (_send (msg->conn, fd) == RSE_OK) + if (msg->conn->callbacks.sent_cb) + msg->conn->callbacks.sent_cb (msg->conn->user_data); } #if defined (DEBUG) @@ -145,7 +145,7 @@ _evcb (evutil_socket_t fd, short what, void *user_data) } int -udp_init (struct rs_connection *conn, struct rs_packet *pkt) +udp_init (struct rs_connection *conn, struct rs_message *msg) { assert (!conn->bev); @@ -1,5 +1,5 @@ /* Copyright 2011 NORDUnet A/S. All rights reserved. See LICENSE for licensing information. */ -int udp_init (struct rs_connection *conn, struct rs_packet *pkt); +int udp_init (struct rs_connection *conn, struct rs_message *msg); int udp_init_retransmit_timer (struct rs_connection *conn); |