NETWORK ATTACKS FRAMEWORK  1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
NA_nl.h File Reference

Go to the source code of this file.

Functions

void nl_init (void)
void nl_cleanup (void)
int nl_send_add_route_msg (struct in_addr dest, struct in_addr next_hop, int metric, u_int32_t lifetime, int rt_flags, int ifindex)
int nl_send_del_route_msg (struct in_addr dest, struct in_addr next_hop, int metric)
int nl_send_no_route_found_msg (struct in_addr dest)
int nl_send_conf_msg (void)

Function Documentation

void nl_cleanup ( void  )

Definition at line 155 of file NA_nl.c.

{
        close(aodvnl.sock);
        close(rtnl.sock);
}
void nl_init ( void  )

Definition at line 73 of file NA_nl.c.

{
        int status;
        unsigned int addrlen;

        memset(&peer, 0, sizeof(struct sockaddr_nl));
        peer.nl_family = AF_NETLINK;
        peer.nl_pid = 0;
        peer.nl_groups = 0;

        memset(&aodvnl, 0, sizeof(struct nlsock));
        aodvnl.seq = 0;
        aodvnl.local.nl_family = AF_NETLINK;
        aodvnl.local.nl_groups = AODVGRP_NOTIFY;
        aodvnl.local.nl_pid = getpid();

        /* This is the AODV specific socket to communicate with the
           AODV kernel module */
        aodvnl.sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_AODV);

        if (aodvnl.sock < 0) {
                perror("Unable to create AODV netlink socket");
                exit(-1);
        }


        status = bind(aodvnl.sock, (struct sockaddr *) &aodvnl.local,
                      sizeof(aodvnl.local));

        if (status == -1) {
                perror("Bind for AODV netlink socket failed");
                exit(-1);
        }

        addrlen = sizeof(aodvnl.local);

        if (getsockname
            (aodvnl.sock, (struct sockaddr *) &aodvnl.local, &addrlen) < 0) {
                perror("Getsockname failed ");
                exit(-1);
        }

        if (attach_callback_func(aodvnl.sock, nl_kaodv_callback) < 0) {
                alog(LOG_ERR, 0, __FUNCTION__, "Could not attach callback.");
        }
        /* This socket is the generic routing socket for adding and
           removing kernel routing table entries */

        memset(&rtnl, 0, sizeof(struct nlsock));
        rtnl.seq = 0;
        rtnl.local.nl_family = AF_NETLINK;
        rtnl.local.nl_groups =
            RTMGRP_NOTIFY | RTMGRP_IPV4_IFADDR | RTMGRP_IPV4_ROUTE;
        rtnl.local.nl_pid = getpid();

        rtnl.sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);

        if (rtnl.sock < 0) {
                perror("Unable to create RT netlink socket");
                exit(-1);
        }

        addrlen = sizeof(rtnl.local);

        status = bind(rtnl.sock, (struct sockaddr *) &rtnl.local, addrlen);

        if (status == -1) {
                perror("Bind for RT netlink socket failed");
                exit(-1);
        }

        if (getsockname(rtnl.sock, (struct sockaddr *) &rtnl.local, &addrlen) <
            0) {
                perror("Getsockname failed ");
                exit(-1);
        }

        if (attach_callback_func(rtnl.sock, nl_rt_callback) < 0) {
                alog(LOG_ERR, 0, __FUNCTION__, "Could not attach callback.");
        }
}
int nl_send_add_route_msg ( struct in_addr  dest,
struct in_addr  next_hop,
int  metric,
u_int32_t  lifetime,
int  rt_flags,
int  ifindex 
)

Definition at line 489 of file NA_nl.c.

{
        struct {
                struct nlmsghdr n;
                struct kaodv_rt_msg m;
        } areq;

        DEBUG(LOG_DEBUG, 0, "ADD/UPDATE: %s:%s ifindex=%d",
              ip_to_str(dest), ip_to_str(next_hop), ifindex);

        memset(&areq, 0, sizeof(areq));

        areq.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct kaodv_rt_msg));
        areq.n.nlmsg_type = KAODVM_ADDROUTE;
        areq.n.nlmsg_flags = NLM_F_REQUEST;

        areq.m.dst = dest.s_addr;
        areq.m.nhop = next_hop.s_addr;
        areq.m.time = lifetime;
        areq.m.ifindex = ifindex;

        if (rt_flags & RT_INET_DEST) {
                areq.m.flags |= KAODV_RT_GW_ENCAP;
        }

        if (rt_flags & RT_REPAIR)
                areq.m.flags |= KAODV_RT_REPAIR;

        if (nl_send(&aodvnl, &areq.n) < 0) {
                DEBUG(LOG_DEBUG, 0, "Failed to send netlink message");
                return -1;
        }
#ifdef DEBUG_NETLINK
        DEBUG(LOG_DEBUG, 0, "Sending add route");
#endif
        return nl_kern_route(RTM_NEWROUTE, NLM_F_CREATE,
                             AF_INET, ifindex, &dest, &next_hop, NULL, metric);
}
int nl_send_conf_msg ( void  )

Definition at line 583 of file NA_nl.c.

{
        struct {
                struct nlmsghdr n;
                kaodv_conf_msg_t cm;
        } areq;

        memset(&areq, 0, sizeof(areq));

        areq.n.nlmsg_len = NLMSG_LENGTH(sizeof(kaodv_conf_msg_t));
        areq.n.nlmsg_type = KAODVM_CONFIG;
        areq.n.nlmsg_flags = NLM_F_REQUEST;

        areq.cm.qual_th = qual_threshold;
        areq.cm.active_route_timeout = active_route_timeout;
        areq.cm.is_gateway = internet_gw_mode;

#ifdef DEBUG_NETLINK
        DEBUG(LOG_DEBUG, 0, "Sending aodv conf msg");
#endif
        return nl_send(&aodvnl, &areq.n);
}
int nl_send_del_route_msg ( struct in_addr  dest,
struct in_addr  next_hop,
int  metric 
)

Definition at line 551 of file NA_nl.c.

{
        int index = -1;
        struct {
                struct nlmsghdr n;
                struct kaodv_rt_msg m;
        } areq;

        DEBUG(LOG_DEBUG, 0, "Send DEL_ROUTE to kernel: %s", ip_to_str(dest));

        memset(&areq, 0, sizeof(areq));

        areq.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct kaodv_rt_msg));
        areq.n.nlmsg_type = KAODVM_DELROUTE;
        areq.n.nlmsg_flags = NLM_F_REQUEST;

        areq.m.dst = dest.s_addr;
        areq.m.nhop = next_hop.s_addr;
        areq.m.time = 0;
        areq.m.flags = 0;

        if (nl_send(&aodvnl, &areq.n) < 0) {
                DEBUG(LOG_DEBUG, 0, "Failed to send netlink message");
                return -1;
        }
#ifdef DEBUG_NETLINK
        DEBUG(LOG_DEBUG, 0, "Sending del route");
#endif
        return nl_kern_route(RTM_DELROUTE, 0, AF_INET, index, &dest, &next_hop,
                             NULL, metric);
}
int nl_send_no_route_found_msg ( struct in_addr  dest)

Definition at line 530 of file NA_nl.c.

{
        struct {
                struct nlmsghdr n;
                kaodv_rt_msg_t m;
        } areq;

        memset(&areq, 0, sizeof(areq));

        areq.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct kaodv_rt_msg));
        areq.n.nlmsg_type = KAODVM_NOROUTE_FOUND;
        areq.n.nlmsg_flags = NLM_F_REQUEST;

        areq.m.dst = dest.s_addr;

        DEBUG(LOG_DEBUG, 0, "Send NOROUTE_FOUND to kernel: %s",
              ip_to_str(dest));

        return nl_send(&aodvnl, &areq.n);
}
 All Classes Files Functions Variables Typedefs Enumerator Defines