2019-06-24 09:33:16 +00:00
|
|
|
|
#ifndef LIBNETLINKK_K_H
|
|
|
|
|
#define LIBNETLINKK_K_H
|
|
|
|
|
|
2019-06-11 03:21:35 +00:00
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
#include <linux/netlink.h>
|
|
|
|
|
#include <linux/netfilter.h>
|
|
|
|
|
#include <linux/ip.h>
|
|
|
|
|
#include <uapi/linux/netfilter_ipv4.h>
|
|
|
|
|
#include <uapi/linux/ip.h>
|
|
|
|
|
#include <net/netlink.h>
|
|
|
|
|
#include <net/net_namespace.h>
|
2019-06-21 02:35:43 +00:00
|
|
|
|
#include "../../../Common/commuapinl.h"
|
2019-06-11 03:21:35 +00:00
|
|
|
|
|
2019-06-28 07:08:54 +00:00
|
|
|
|
#define NETLINK_DEBUG(debugfs_enable, ...) \
|
|
|
|
|
if(DEBUGFS_PRK_ONOFF != debugfs_enable) printk(__VA_ARGS__)
|
|
|
|
|
|
2019-06-11 03:21:35 +00:00
|
|
|
|
|
|
|
|
|
struct netlinkk_cfg
|
|
|
|
|
{
|
|
|
|
|
struct netlink_kernel_cfg cfg;
|
|
|
|
|
|
|
|
|
|
struct sock *sk; //内核端socket
|
|
|
|
|
int user_pid;/*用户态pid*/
|
|
|
|
|
unsigned int subscriptions;/*netlink总线,netlink协议号*/
|
|
|
|
|
unsigned int groups;/*netlink 组播组*/
|
2019-06-21 09:02:36 +00:00
|
|
|
|
struct netlink_debugfs dfs;
|
2019-06-25 06:42:36 +00:00
|
|
|
|
struct commnl_msgtype_process* msg_processer;
|
|
|
|
|
int msg_processer_num;
|
2019-06-28 07:08:54 +00:00
|
|
|
|
unsigned long debugfs_prk_enable;
|
2019-06-11 03:21:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-06-21 02:35:43 +00:00
|
|
|
|
typedef int (*commnl_doit_func)(struct sk_buff *, struct nlmsghdr *,struct netlink_ext_ack *);
|
|
|
|
|
typedef int (*commnl_dumpit_func)(struct sk_buff *, struct netlink_callback *,struct netlink_ext_ack *);
|
|
|
|
|
typedef u16 (*commnl_calcit_func)(struct sk_buff *, struct nlmsghdr *,struct netlink_ext_ack *);
|
2019-06-11 03:21:35 +00:00
|
|
|
|
|
|
|
|
|
struct commnl_msgtype_process
|
|
|
|
|
{
|
|
|
|
|
int msgtype;
|
|
|
|
|
commnl_doit_func doit;
|
|
|
|
|
commnl_dumpit_func dumpit;
|
|
|
|
|
commnl_calcit_func calcit;
|
2019-06-21 09:02:36 +00:00
|
|
|
|
struct netlink_debugfs dfs;
|
2019-06-11 03:21:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-13 06:55:31 +00:00
|
|
|
|
extern void printk_mem(unsigned char * p,int len);
|
|
|
|
|
extern void printk_ipaddress(unsigned int address);
|
2019-06-11 03:21:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************/
|
|
|
|
|
/*函数功能:注册内核态配置接收消息处理函数。 */
|
|
|
|
|
/*输入参数: */
|
|
|
|
|
/*msgtype:注册的消息类型。*/
|
|
|
|
|
/*doit:对应的消息接收处理函数;*/
|
|
|
|
|
/*dumpit,calcit:框架预留接口,暂未使用。填NULL.*/
|
|
|
|
|
/*输出参数: WU */
|
|
|
|
|
/*返回值:0注册成功;< 0,失败 */
|
|
|
|
|
/****************************************************************/
|
2019-06-21 09:02:36 +00:00
|
|
|
|
int commnl_register(struct commnl_msgtype_process *msg_handlers, int msgtype,
|
|
|
|
|
commnl_doit_func doit, commnl_dumpit_func dumpit,
|
|
|
|
|
commnl_calcit_func calcit);
|
2019-06-11 03:21:35 +00:00
|
|
|
|
|
2019-06-21 09:02:36 +00:00
|
|
|
|
int commnl_unregister(struct commnl_msgtype_process *msg_handlers, int msgtype);
|
2019-06-11 03:21:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************/
|
|
|
|
|
/*函数功能:在内核态创建报文上送通道,上送的 */
|
|
|
|
|
/*报文内容从链路层头开始。一个netlink协议号只能创建一个通道。 */
|
|
|
|
|
/*输入参数:g_nlcfg */
|
|
|
|
|
/*输出参数: struct upmnl_handle * upmh ,存放创建的通道相关信息。*/
|
|
|
|
|
/*返回值:0通道创建成果;< 0,失败 */
|
|
|
|
|
/****************************************************************/
|
2019-06-13 06:55:31 +00:00
|
|
|
|
extern int libnetlinkk_init_byproto(struct netlinkk_cfg *g_nlcfg);
|
2019-06-11 03:21:35 +00:00
|
|
|
|
|
2019-06-13 06:55:31 +00:00
|
|
|
|
extern void libnetlinkk_exit(struct netlinkk_cfg *g_nlcfg);
|
2019-06-11 03:21:35 +00:00
|
|
|
|
|
2019-06-13 06:55:31 +00:00
|
|
|
|
extern int commnl_unicast(struct sock *sk, struct sk_buff *skb, u32 portid);
|
2019-06-11 03:21:35 +00:00
|
|
|
|
|
2019-06-21 02:35:43 +00:00
|
|
|
|
extern int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg,
|
|
|
|
|
struct nlmsghdr *nlh,struct netlink_ext_ack *extack);
|
2019-06-21 09:02:36 +00:00
|
|
|
|
|
2019-06-21 02:35:43 +00:00
|
|
|
|
extern int debugfs_pkt_num_stati_witisend(struct netlinkk_cfg *g_nlcfg,
|
2019-06-21 09:02:36 +00:00
|
|
|
|
struct nlmsghdr *nlh,struct commnl_msgtype_process* msg_process);
|
|
|
|
|
|
2019-06-20 03:20:46 +00:00
|
|
|
|
|
|
|
|
|
extern int nf_nlmsg_multicast(struct netlinkk_cfg *g_nlcfg, struct sk_buff *skb);
|
|
|
|
|
|
2019-06-28 07:08:54 +00:00
|
|
|
|
extern int debugfs_prk_onoff(struct netlinkk_cfg *g_nlcfg,
|
|
|
|
|
struct nlmsghdr *nlh,struct netlink_ext_ack *extack);
|
|
|
|
|
|
2019-06-24 09:33:16 +00:00
|
|
|
|
#endif
|
2019-06-11 03:21:35 +00:00
|
|
|
|
|