summaryrefslogtreecommitdiff
path: root/libndp
diff options
context:
space:
mode:
authorJiri Pirko <jiri@resnulli.us>2013-03-16 18:33:27 +0100
committerJiri Pirko <jiri@resnulli.us>2013-03-17 11:11:48 +0100
commitdfed476eee192e86c140298810bb598c927645e8 (patch)
tree5259fb6bf48b42abe9dbaabb5f613e88d40ca68b /libndp
parent3407d519b8eb9a2cda25eefcd53bf4ce950a5d64 (diff)
downloadlibndp-dfed476eee192e86c140298810bb598c927645e8.tar.gz
lib: setup first pointer in all type-specific structures at once
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Diffstat (limited to 'libndp')
-rw-r--r--libndp/libndp.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/libndp/libndp.c b/libndp/libndp.c
index a9e4a69..8fcdb2c 100644
--- a/libndp/libndp.c
+++ b/libndp/libndp.c
@@ -234,11 +234,16 @@ static void ndp_sock_close(struct ndp *ndp)
close(ndp->sock);
}
+struct ndp_msggeneric {
+ void *dataptr; /* must be first */
+};
+
struct ndp_msgrs {
+ struct nd_router_solicit *rs; /* must be first */
};
struct ndp_msgra {
- struct nd_router_advert *ra;
+ struct nd_router_advert *ra; /* must be first */
struct {
bool present;
unsigned char addr[ETH_ALEN];
@@ -649,12 +654,15 @@ uint32_t ndp_msgra_opt_mtu(struct ndp_msgra *msgra)
}
struct ndp_msgns {
+ struct nd_neighbor_solicit *ns; /* must be first */
};
struct ndp_msgna {
+ struct nd_neighbor_solicit *na; /* must be first */
};
struct ndp_msgr {
+ struct nd_redirect *r; /* must be first */
};
struct ndp_msg {
@@ -667,6 +675,7 @@ struct ndp_msg {
unsigned char * opts_start; /* pointer to buf at the
place where opts start */
union {
+ struct ndp_msggeneric generic;
struct ndp_msgrs rs;
struct ndp_msgra ra;
struct ndp_msgns ns;
@@ -751,6 +760,11 @@ static void ndp_msg_init(struct ndp_msg *msg, enum ndp_msg_type msg_type)
ndp_msg_type_set(msg, msg_type);
msg->opts_start = msg->buf +
ndp_msg_type_info(msg_type)->raw_struct_size;
+
+ /* Set-up "first pointers" in all ndp_msgrs, ndp_msgra, ndp_msgns,
+ * ndp_msgna, ndp_msgr structures.
+ */
+ msg->nd_msg.generic.dataptr = ndp_msg_payload(msg);
}
/**
@@ -1036,8 +1050,6 @@ static void ndp_process_ra(struct ndp *ndp, struct ndp_msg *msg)
size_t len = ndp_msg_payload_len(msg);
unsigned char *ptr;
- msgra->ra = ndp_msg_payload(msg);
-
ptr = ndp_msg_payload_opts(msg);
len = ndp_msg_payload_opts_len(msg);
while (len > 0) {