summaryrefslogtreecommitdiff
path: root/libndp
diff options
context:
space:
mode:
authorJiri Pirko <jiri@resnulli.us>2013-03-17 10:44:58 +0100
committerJiri Pirko <jiri@resnulli.us>2013-03-17 11:11:48 +0100
commit65e5f7aa92359892004625f6ed1c7f5c90dae6ff (patch)
tree3ee9edf2fc8485a7fa67aa4a6be25d6a8c12f817 /libndp
parentb2164948b972fc09fcbd26dfdfd011a1773384a7 (diff)
downloadlibndp-65e5f7aa92359892004625f6ed1c7f5c90dae6ff.tar.gz
lib: init msg->len accorsding to ND type during init and introduce maxlen getter
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Diffstat (limited to 'libndp')
-rw-r--r--libndp/libndp.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/libndp/libndp.c b/libndp/libndp.c
index 4fb75a1..56cecb1 100644
--- a/libndp/libndp.c
+++ b/libndp/libndp.c
@@ -805,7 +805,6 @@ static struct ndp_msg *ndp_msg_alloc(void)
msg = myzalloc(sizeof(*msg));
if (!msg)
return NULL;
- msg->len = sizeof(msg->buf);
msg->icmp6_hdr = (struct icmp6_hdr *) msg->buf;
return msg;
}
@@ -814,9 +813,11 @@ static void ndp_msg_type_set(struct ndp_msg *msg, enum ndp_msg_type msg_type);
static void ndp_msg_init(struct ndp_msg *msg, enum ndp_msg_type msg_type)
{
+ size_t raw_struct_size = ndp_msg_type_info(msg_type)->raw_struct_size;
+
ndp_msg_type_set(msg, msg_type);
- msg->opts_start = msg->buf +
- ndp_msg_type_info(msg_type)->raw_struct_size;
+ msg->len = raw_struct_size;
+ msg->opts_start = msg->buf + raw_struct_size;
/* Set-up "first pointers" in all ndp_msgrs, ndp_msgra, ndp_msgns,
* ndp_msgna, ndp_msgr structures.
@@ -874,6 +875,20 @@ void *ndp_msg_payload(struct ndp_msg *msg)
}
/**
+ * ndp_msg_payload_maxlen:
+ * @msg: message structure
+ *
+ * Get raw Neighbour discovery packet data maximum length.
+ *
+ * Returns: length in bytes.
+ **/
+NDP_EXPORT
+size_t ndp_msg_payload_maxlen(struct ndp_msg *msg)
+{
+ return sizeof(msg->buf);
+}
+
+/**
* ndp_msg_payload_len:
* @msg: message structure
*
@@ -1160,13 +1175,14 @@ static int ndp_sock_recv(struct ndp *ndp)
{
struct ndp_msg *msg;
enum ndp_msg_type msg_type;
- size_t len = sizeof(msg->buf);
+ size_t len;
int err;
msg = ndp_msg_alloc();
if (!msg)
return -ENOMEM;
+ len = ndp_msg_payload_maxlen(msg);
err = myrecvfrom6(ndp->sock, msg->buf, &len, 0,
&msg->addrto, &msg->ifindex);
if (err) {
@@ -1176,8 +1192,6 @@ static int ndp_sock_recv(struct ndp *ndp)
dbg(ndp, "rcvd from: %s, ifindex: %u",
str_in6_addr(&msg->addrto), msg->ifindex);
- ndp_msg_payload_len_set(msg, len);
-
if (len < sizeof(*msg->icmp6_hdr)) {
warn(ndp, "rcvd icmp6 packet too short (%luB)", len);
err = 0;
@@ -1187,6 +1201,7 @@ static int ndp_sock_recv(struct ndp *ndp)
if (err)
goto free_msg;
ndp_msg_init(msg, msg_type);
+ ndp_msg_payload_len_set(msg, len);
if (len < ndp_msg_type_info(msg_type)->raw_struct_size) {
warn(ndp, "rcvd %s packet too short (%luB)",