diff --git a/dataplane/kernel/genetlink/genetlink.c b/dataplane/kernel/genetlink/genetlink.c index 0d39d652..0b075659 100644 --- a/dataplane/kernel/genetlink/genetlink.c +++ b/dataplane/kernel/genetlink/genetlink.c @@ -20,8 +20,7 @@ #include #include #include - -#include "stdlib.h" +#include enum { /* packet metadata */ @@ -31,29 +30,24 @@ enum { GENL_PACKET_ATTR_DATA, }; -struct nl_sock** nlsocks = NULL; -int* families = NULL; -int create_idx = 0; -const int max_sockets = 20; - struct nl_sock* create_port(const char* family, const char* group) { fprintf(stderr, "creating port\n"); struct nl_sock* sock = nl_socket_alloc(); if (sock == NULL) { - fprintf(stderr,"error: failed to alloc nl socket"); + fprintf(stderr, "error: failed to alloc nl socket"); return NULL; } nl_socket_disable_auto_ack(sock); int error = genl_connect(sock); if (error < 0) { - fprintf(stderr,"error: failed to disable auto ack"); + fprintf(stderr, "error: failed to disable auto ack"); nl_socket_free(sock); return NULL; } int group_id = genl_ctrl_resolve_grp(sock, family, group); if (group_id < 0) { - fprintf(stderr,"error: failed to resolve group"); + fprintf(stderr, "error: failed to resolve group"); nl_socket_free(sock); return NULL; } @@ -61,21 +55,19 @@ struct nl_sock* create_port(const char* family, const char* group) { return sock; } -void delete_port(void * sock) { - nl_socket_free(sock); -} +void delete_port(void* sock) { nl_socket_free(sock); } -int send_packet(void* sock, int family, const void* pkt, uint32_t size, int in_ifindex, - int out_ifindex, unsigned int context) { +int send_packet(void* sock, int family, const void* pkt, uint32_t size, + int in_ifindex, int out_ifindex, unsigned int context) { struct nl_msg* msg = nlmsg_alloc(); genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, family, 0, 0, 0, 1); NLA_PUT_S16(msg, GENL_PACKET_ATTR_IIFINDEX, in_ifindex); NLA_PUT_S16(msg, GENL_PACKET_ATTR_OIFINDEX, out_ifindex); NLA_PUT_U32(msg, GENL_PACKET_ATTR_CONTEXT, context); NLA_PUT(msg, GENL_PACKET_ATTR_DATA, size, pkt); - fprintf(stderr,"sending packet size: %d\n", size); + fprintf(stderr, "sending packet size: %d\n", size); if (nl_send(sock, msg) < 0) { - fprintf(stderr,"failed to send packet\n"); + fprintf(stderr, "failed to send packet\n"); return -1; } nlmsg_free(msg); @@ -83,4 +75,4 @@ int send_packet(void* sock, int family, const void* pkt, uint32_t size, int in_i nla_put_failure: nlmsg_free(msg); return -1; -} \ No newline at end of file +} diff --git a/dataplane/kernel/genetlink/genetlink.h b/dataplane/kernel/genetlink/genetlink.h index d2fde10d..b2c760ff 100644 --- a/dataplane/kernel/genetlink/genetlink.h +++ b/dataplane/kernel/genetlink/genetlink.h @@ -12,18 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef DATAPLANE_KERNEL_GENETLINK_H_ -#define DATAPLANE_KERNEL_GENETLINK_H_ +#ifndef DATAPLANE_KERNEL_GENETLINK_GENETLINK_H_ +#define DATAPLANE_KERNEL_GENETLINK_GENETLINK_H_ #include // create_port create genetlink socket. struct nl_sock* create_port(const char* family, const char* group); -void delete_port(void * sock); +void delete_port(void* sock); // send_packet sends a packet with given metadata to specified port. -int send_packet(void* sock, int family, const void* pkt, uint32_t size, int in_ifindex, int out_ifindex, - unsigned int context); +int send_packet(void* sock, int family, const void* pkt, uint32_t size, + int in_ifindex, int out_ifindex, unsigned int context); -#endif \ No newline at end of file +#endif