kernel-netlink: Avoid casting the NLMSG_DATA() return value
authorMartin Willi <martin@revosec.ch>
Wed, 9 Jul 2014 13:53:14 +0000 (15:53 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 24 Sep 2014 09:19:59 +0000 (11:19 +0200)
There is really no need for doing so, and it makes the code just unreadable.

src/libhydra/plugins/kernel_netlink/kernel_netlink_ipsec.c
src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c
src/libhydra/plugins/kernel_netlink/kernel_netlink_shared.c

index b00c041..cd94168 100644 (file)
@@ -816,7 +816,7 @@ static void process_acquire(private_kernel_netlink_ipsec_t *this,
        u_int32_t reqid = 0;
        int proto = 0;
 
-       acquire = (struct xfrm_user_acquire*)NLMSG_DATA(hdr);
+       acquire = NLMSG_DATA(hdr);
        rta = XFRM_RTA(hdr, struct xfrm_user_acquire);
        rtasize = XFRM_PAYLOAD(hdr, struct xfrm_user_acquire);
 
@@ -862,7 +862,7 @@ static void process_expire(private_kernel_netlink_ipsec_t *this,
        u_int32_t spi, reqid;
        u_int8_t protocol;
 
-       expire = (struct xfrm_user_expire*)NLMSG_DATA(hdr);
+       expire = NLMSG_DATA(hdr);
        protocol = expire->state.id.proto;
        spi = expire->state.id.spi;
        reqid = expire->state.reqid;
@@ -896,7 +896,7 @@ static void process_migrate(private_kernel_netlink_ipsec_t *this,
        u_int32_t reqid = 0;
        policy_dir_t dir;
 
-       policy_id = (struct xfrm_userpolicy_id*)NLMSG_DATA(hdr);
+       policy_id = NLMSG_DATA(hdr);
        rta     = XFRM_RTA(hdr, struct xfrm_userpolicy_id);
        rtasize = XFRM_PAYLOAD(hdr, struct xfrm_userpolicy_id);
 
@@ -963,7 +963,7 @@ static void process_mapping(private_kernel_netlink_ipsec_t *this,
        struct xfrm_user_mapping *mapping;
        u_int32_t spi, reqid;
 
-       mapping = (struct xfrm_user_mapping*)NLMSG_DATA(hdr);
+       mapping = NLMSG_DATA(hdr);
        spi = mapping->id.spi;
        reqid = mapping->reqid;
 
@@ -1070,7 +1070,7 @@ static status_t get_spi_internal(private_kernel_netlink_ipsec_t *this,
        hdr->nlmsg_type = XFRM_MSG_ALLOCSPI;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct xfrm_userspi_info));
 
-       userspi = (struct xfrm_userspi_info*)NLMSG_DATA(hdr);
+       userspi = NLMSG_DATA(hdr);
        host2xfrm(src, &userspi->info.saddr);
        host2xfrm(dst, &userspi->info.id.daddr);
        userspi->info.id.proto = proto;
@@ -1219,7 +1219,7 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
        hdr->nlmsg_type = inbound ? XFRM_MSG_UPDSA : XFRM_MSG_NEWSA;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct xfrm_usersa_info));
 
-       sa = (struct xfrm_usersa_info*)NLMSG_DATA(hdr);
+       sa = NLMSG_DATA(hdr);
        host2xfrm(src, &sa->saddr);
        host2xfrm(dst, &sa->id.daddr);
        sa->id.spi = spi;
@@ -1554,7 +1554,7 @@ static void get_replay_state(private_kernel_netlink_ipsec_t *this,
        hdr->nlmsg_type = XFRM_MSG_GETAE;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct xfrm_aevent_id));
 
-       aevent_id = (struct xfrm_aevent_id*)NLMSG_DATA(hdr);
+       aevent_id = NLMSG_DATA(hdr);
        aevent_id->flags = XFRM_AE_RVAL;
 
        host2xfrm(dst, &aevent_id->sa_id.daddr);
@@ -1646,7 +1646,7 @@ METHOD(kernel_ipsec_t, query_sa, status_t,
        hdr->nlmsg_type = XFRM_MSG_GETSA;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct xfrm_usersa_id));
 
-       sa_id = (struct xfrm_usersa_id*)NLMSG_DATA(hdr);
+       sa_id = NLMSG_DATA(hdr);
        host2xfrm(dst, &sa_id->daddr);
        sa_id->spi = spi;
        sa_id->proto = protocol;
@@ -1666,7 +1666,7 @@ METHOD(kernel_ipsec_t, query_sa, status_t,
                        {
                                case XFRM_MSG_NEWSA:
                                {
-                                       sa = (struct xfrm_usersa_info*)NLMSG_DATA(hdr);
+                                       sa = NLMSG_DATA(hdr);
                                        break;
                                }
                                case NLMSG_ERROR:
@@ -1749,7 +1749,7 @@ METHOD(kernel_ipsec_t, del_sa, status_t,
        hdr->nlmsg_type = XFRM_MSG_DELSA;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct xfrm_usersa_id));
 
-       sa_id = (struct xfrm_usersa_id*)NLMSG_DATA(hdr);
+       sa_id = NLMSG_DATA(hdr);
        host2xfrm(dst, &sa_id->daddr);
        sa_id->spi = spi;
        sa_id->proto = protocol;
@@ -1818,7 +1818,7 @@ METHOD(kernel_ipsec_t, update_sa, status_t,
        hdr->nlmsg_type = XFRM_MSG_GETSA;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct xfrm_usersa_id));
 
-       sa_id = (struct xfrm_usersa_id*)NLMSG_DATA(hdr);
+       sa_id = NLMSG_DATA(hdr);
        host2xfrm(dst, &sa_id->daddr);
        sa_id->spi = spi;
        sa_id->proto = protocol;
@@ -1989,7 +1989,7 @@ METHOD(kernel_ipsec_t, flush_sas, status_t,
        hdr->nlmsg_type = XFRM_MSG_FLUSHSA;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct xfrm_usersa_flush));
 
-       flush = (struct xfrm_usersa_flush*)NLMSG_DATA(hdr);
+       flush = NLMSG_DATA(hdr);
        flush->proto = IPSEC_PROTO_ANY;
 
        if (this->socket_xfrm->send_ack(this->socket_xfrm, hdr) != SUCCESS)
@@ -2025,7 +2025,7 @@ static status_t add_policy_internal(private_kernel_netlink_ipsec_t *this,
        hdr->nlmsg_type = update ? XFRM_MSG_UPDPOLICY : XFRM_MSG_NEWPOLICY;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct xfrm_userpolicy_info));
 
-       policy_info = (struct xfrm_userpolicy_info*)NLMSG_DATA(hdr);
+       policy_info = NLMSG_DATA(hdr);
        policy_info->sel = policy->sel;
        policy_info->dir = policy->direction;
 
@@ -2349,7 +2349,7 @@ METHOD(kernel_ipsec_t, query_policy, status_t,
        hdr->nlmsg_type = XFRM_MSG_GETPOLICY;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct xfrm_userpolicy_id));
 
-       policy_id = (struct xfrm_userpolicy_id*)NLMSG_DATA(hdr);
+       policy_id = NLMSG_DATA(hdr);
        policy_id->sel = ts2selector(src_ts, dst_ts);
        policy_id->dir = direction;
 
@@ -2367,7 +2367,7 @@ METHOD(kernel_ipsec_t, query_policy, status_t,
                        {
                                case XFRM_MSG_NEWPOLICY:
                                {
-                                       policy = (struct xfrm_userpolicy_info*)NLMSG_DATA(hdr);
+                                       policy = NLMSG_DATA(hdr);
                                        break;
                                }
                                case NLMSG_ERROR:
@@ -2506,7 +2506,7 @@ METHOD(kernel_ipsec_t, del_policy, status_t,
        hdr->nlmsg_type = XFRM_MSG_DELPOLICY;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct xfrm_userpolicy_id));
 
-       policy_id = (struct xfrm_userpolicy_id*)NLMSG_DATA(hdr);
+       policy_id = NLMSG_DATA(hdr);
        policy_id->sel = current->sel;
        policy_id->dir = direction;
 
index ccb097e..3d5538c 100644 (file)
@@ -938,7 +938,7 @@ static void addr_entry_unregister(addr_entry_t *addr, iface_entry_t *iface,
 static void process_link(private_kernel_netlink_net_t *this,
                                                 struct nlmsghdr *hdr, bool event)
 {
-       struct ifinfomsg* msg = (struct ifinfomsg*)(NLMSG_DATA(hdr));
+       struct ifinfomsg* msg = NLMSG_DATA(hdr);
        struct rtattr *rta = IFLA_RTA(msg);
        size_t rtasize = IFLA_PAYLOAD (hdr);
        enumerator_t *enumerator;
@@ -1040,7 +1040,7 @@ static void process_link(private_kernel_netlink_net_t *this,
 static void process_addr(private_kernel_netlink_net_t *this,
                                                 struct nlmsghdr *hdr, bool event)
 {
-       struct ifaddrmsg* msg = (struct ifaddrmsg*)(NLMSG_DATA(hdr));
+       struct ifaddrmsg* msg = NLMSG_DATA(hdr);
        struct rtattr *rta = IFA_RTA(msg);
        size_t rtasize = IFA_PAYLOAD (hdr);
        host_t *host = NULL;
@@ -1183,7 +1183,7 @@ static void process_addr(private_kernel_netlink_net_t *this,
  */
 static void process_route(private_kernel_netlink_net_t *this, struct nlmsghdr *hdr)
 {
-       struct rtmsg* msg = (struct rtmsg*)(NLMSG_DATA(hdr));
+       struct rtmsg* msg = NLMSG_DATA(hdr);
        struct rtattr *rta = RTM_RTA(msg);
        size_t rtasize = RTM_PAYLOAD(hdr);
        u_int32_t rta_oif = 0;
@@ -1540,7 +1540,7 @@ static rt_entry_t *parse_route(struct nlmsghdr *hdr, rt_entry_t *route)
        struct rtmsg *msg;
        size_t rtasize;
 
-       msg = (struct rtmsg*)(NLMSG_DATA(hdr));
+       msg = NLMSG_DATA(hdr);
        rta = RTM_RTA(msg);
        rtasize = RTM_PAYLOAD(hdr);
 
@@ -1637,7 +1637,7 @@ static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest,
        hdr->nlmsg_type = RTM_GETROUTE;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
 
-       msg = (struct rtmsg*)NLMSG_DATA(hdr);
+       msg = NLMSG_DATA(hdr);
        msg->rtm_family = family;
        if (candidate)
        {
@@ -1869,7 +1869,7 @@ static status_t manage_ipaddr(private_kernel_netlink_net_t *this, int nlmsg_type
        hdr->nlmsg_type = nlmsg_type;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
 
-       msg = (struct ifaddrmsg*)NLMSG_DATA(hdr);
+       msg = NLMSG_DATA(hdr);
        msg->ifa_family = ip->get_family(ip);
        msg->ifa_flags = 0;
        msg->ifa_prefixlen = prefix < 0 ? chunk.len * 8 : prefix;
@@ -2097,7 +2097,7 @@ static status_t manage_srcroute(private_kernel_netlink_net_t *this,
        hdr->nlmsg_type = nlmsg_type;
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
 
-       msg = (struct rtmsg*)NLMSG_DATA(hdr);
+       msg = NLMSG_DATA(hdr);
        msg->rtm_family = src_ip->get_family(src_ip);
        msg->rtm_dst_len = prefixlen;
        msg->rtm_table = this->routing_table;
@@ -2224,7 +2224,7 @@ static status_t init_address_list(private_kernel_netlink_net_t *this)
        in = &request.hdr;
        in->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));
        in->nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH | NLM_F_ROOT;
-       msg = (struct rtgenmsg*)NLMSG_DATA(in);
+       msg = NLMSG_DATA(in);
        msg->rtgen_family = AF_UNSPEC;
 
        /* get all links */
@@ -2317,7 +2317,7 @@ static status_t manage_rule(private_kernel_netlink_net_t *this, int nlmsg_type,
        }
        hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
 
-       msg = (struct rtmsg*)NLMSG_DATA(hdr);
+       msg = NLMSG_DATA(hdr);
        msg->rtm_table = table;
        msg->rtm_family = family;
        msg->rtm_protocol = RTPROT_BOOT;
index fd00c23..30d5aaa 100644 (file)
@@ -197,7 +197,7 @@ METHOD(netlink_socket_t, netlink_send_ack, status_t,
                {
                        case NLMSG_ERROR:
                        {
-                               struct nlmsgerr* err = (struct nlmsgerr*)NLMSG_DATA(hdr);
+                               struct nlmsgerr* err = NLMSG_DATA(hdr);
 
                                if (err->error)
                                {