static int register_family(void) { int error; log_debug("Registering Generic Netlink family..."); strcpy(jool_family.name, GNL_JOOL_FAMILY_NAME); #if LINUX_VERSION_LOWER_THAN(3, 13, 0, 7, 1) error = genl_register_family_with_ops(&jool_family, ops, ARRAY_SIZE(ops)); if (error) { log_err("Couldn't register family!"); return error; } error = genl_register_mc_group(&jool_family, &(mc_groups[0])); if (error) { log_err("Couldn't register multicast group!"); return error; } #else error = genl_register_family_with_ops_groups(&jool_family, ops, mc_groups); if (error) { log_err("Family registration failed: %d", error); return error; } #endif nlcore_init(&jool_family, &mc_groups[0]); return 0; }
static int __init kfm_genl_register(void) { // kernel 3.10.0-229 centos 7.1 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,1) /* for kanas (kernel 4.1.1) */ return genl_register_family_with_ops_groups(&kfm_genl_family, kfm_genl_ops, kfm_mcgrps); #else /* for centos 7.0 (kernel 3.10.0) */ { int ret = 0, i; ret = genl_register_family_with_ops(&kfm_genl_family, kfm_genl_ops, ARRAY_SIZE(kfm_genl_ops)); if (ret) return -1; for (i = 0; i < ARRAY_SIZE(kfm_mcgrps); i++) { ret = genl_register_mc_group(&kfm_genl_family, &kfm_mcgrps[i]); if (ret) { genl_unregister_family(&kfm_genl_family); return -1; } } return 0; } #endif }
int nlhandler_init(void) { int error; #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0) error = genl_register_family_with_ops(&family, ops, ARRAY_SIZE(ops)); #else error = genl_register_family_with_ops(&family, ops); #endif if (error) { log_err("Errcode %d registering the Genetlink family.", error); return error; } genl_init(&family); return 0; }
int vr_genetlink_init(void) { int ret; ret = vr_message_transport_register(&netlink_transport); if (ret) return ret; #if ((LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)) && \ (!(defined(RHEL_MAJOR) && (RHEL_MAJOR >= 7)))) return genl_register_family_with_ops(&vrouter_genl_family, vrouter_genl_ops, ARRAY_SIZE(vrouter_genl_ops)); #else return genl_register_family_with_ops(&vrouter_genl_family, vrouter_genl_ops); #endif }
static int l2tp_nl_init(void) { int err; printk(KERN_INFO "L2TP netlink interface\n"); err = genl_register_family_with_ops(&l2tp_nl_family, l2tp_nl_ops, ARRAY_SIZE(l2tp_nl_ops)); return err; }
int vr_genetlink_init(void) { int ret; ret = vr_message_transport_register(&netlink_transport); if (ret) return ret; return genl_register_family_with_ops(&vrouter_genl_family, vrouter_genl_ops, ARRAY_SIZE(vrouter_genl_ops)); }
int tipc_netlink_start(void) { int res; res = genl_register_family_with_ops(&tipc_genl_family, tipc_genl_ops); if (res) { pr_err("Failed to register netlink interface\n"); return res; } tipc_genl_family_registered = 1; return 0; }
int tipc_netlink_compat_start(void) { int res; res = genl_register_family_with_ops(&tipc_genl_compat_family, tipc_genl_compat_ops); if (res) { pr_err("Failed to register legacy compat interface\n"); return res; } return 0; }
static int __init ipctl_init(void) { int rc; printk(KERN_INFO "ipctl: %s.\n", MOD_VER); rc = genl_register_family_with_ops(&ipctl_gnl_family, ipctl_gnl_ops); if (rc) printk("ipctl: genl_register_family: %d.\n", rc); /* * A non 0 return means init_module failed; module can't be loaded. */ return 0; }
int genetlink_register(void) { int ret = 0; ret = genl_register_family_with_ops(&vswitch_flow_family, vswitch_flow_ops, 1); if (ret) return ret; genl_skb = genlmsg_new(0, GFP_KERNEL); if (genl_skb == NULL) { genetlink_unregister(); } return 0; }
/** * Register a new generic netlink family and the ops */ int genl_exec_init(void) { int err; /*register a generic netlink family int genl_register_family_with_ops(struct genl_family *family, struct genl_ops *ops, size_t n_ops) */ err = genl_register_family_with_ops(&genl_exec_family, genl_exec_ops, ARRAY_SIZE(genl_exec_ops)); if (err) return err; /*test the family is registered successfully*/ genlmsg_skb = genlmsg_new(0, GFP_KERNEL); if (!genlmsg_skb) { genl_unregister_family(&genl_exec_family); return -ENOMEM; } return 0; }
static int __init nlk_init(void) { int rc; printk("nlk_init\n"); /* register new family */ rc = genl_register_family_with_ops(&demo_gnl_family, doc_exmpl_gnl_ops_echo); if (rc != 0) { printk("register family with ops: %i\n", rc); genl_unregister_family(&demo_gnl_family); goto failure; } return 0; failure: printk ("an error occured\n"); return -1; }
int __init dlm_netlink_init(void) { return genl_register_family_with_ops(&family, &dlm_nl_ops, 1); }
int kg2_genl_register(void) { return genl_register_family_with_ops(&kg2_genl_family, kg2_genl_ops, ARRAY_SIZE(kg2_genl_ops)); }
static unsigned int queue_function(unsigned int hooknum, struct sk_buff **skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *)){ #else static unsigned int queue_function(unsigned int hooknum, struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *)){ #endif struct iphdr *iph = NULL; /* * yaplej: Process the packet only, * if it was intended for this host, * is not NULL, * and is an IP packet. * * This limits processing packets to in-bound traffic only! */ /* Rewritten for kernel < and >= 2.6.20 */ #if (LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 20)) if ((skb != NULL) && ((*skb)->pkt_type == PACKET_HOST) && ((*skb)->protocol == htons(ETH_P_IP))){ iph = ip_hdr((*skb)); // access ip header. #else if ((skb != NULL) && ((skb)->pkt_type == PACKET_HOST) && ((skb)->protocol == htons(ETH_P_IP))){ iph = ip_hdr((skb)); // access ip header. #endif /* * yaple: Process only TCP segments. */ if (iph->protocol == IPPROTO_TCP){ /* * Check that the daemon is UP. */ if (daemonstate == UP) { return NF_QUEUE; } } } return NF_ACCEPT; } static struct nf_hook_ops opennop_hook = { // This is a netfilter hook. .hook = queue_function, // Function that executes. /* Rewritten for kernel < and >= 2.6.20 */ #if (LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 20)) .hooknum = NF_IP_FORWARD, // For routed traffic only. #else .hooknum = NF_INET_FORWARD, // For routed ip traffic only. #endif .pf = PF_INET, // Only for IP packets. .priority = NF_IP_PRI_FIRST, // My hook executes first. }; static int __init opennopdrv_init(void){ int err, i; int timespan; size_t n_ops; struct genl_ops *ops; timespan = hbintervals * HBINTERVAL; #if (LINUX_VERSION_CODE > KERNEL_VERSION (3, 1, 2)) printk(KERN_ALERT "[OpenNOPDrv]: Kernel Version >= 3.1.2 \n"); printk(KERN_ALERT "[OpenNOPDrv]: opennop_nl_ops %lu\n", ARRAY_SIZE(opennop_nl_ops)); err = genl_register_family_with_ops(&opennop_nl_family, opennop_nl_ops); if (err != 0){ return err; } #elif (LINUX_VERSION_CODE >= KERNEL_VERSION (3, 0, 0)) printk(KERN_ALERT "[OpenNOPDrv]: Kernel Version >= 3.0.0 \n"); printk(KERN_ALERT "[OpenNOPDrv]: opennop_nl_ops %lu\n", ARRAY_SIZE(opennop_nl_ops)); err = genl_register_family_with_ops(&opennop_nl_family, opennop_nl_ops, ARRAY_SIZE(opennop_nl_ops)); if (err != 0){ return err; } #elif (LINUX_VERSION_CODE < KERNEL_VERSION (3, 0, 0)) printk(KERN_ALERT "[OpenNOPDrv]: Kernel Version < 3.0.0 \n"); err = genl_register_family(&opennop_nl_family); if (err != 0){ return err; } printk(KERN_ALERT "[OpenNOPDrv]: opennop_nl_ops %lu\n", ARRAY_SIZE(opennop_nl_ops)); n_ops = ARRAY_SIZE(opennop_nl_ops); ops = (struct genl_ops *)opennop_nl_ops; for (i = 0; i < n_ops; ++i, ++ops) { err = genl_register_ops(&opennop_nl_family, ops); if (err != 0){ return err; } } #else printk(KERN_ALERT "[OpenNOPDrv]: Kernel Version ERROR.\n"); return -1; #endif if (strcmp(mode, "bridged") == 0) { //printk(KERN_ALERT "[OpenNOPDrv]: Switching to bridged mode. \n"); /* Rewritten for kernel < and >= 2.6.30 */ #if (LINUX_VERSION_CODE > KERNEL_VERSION (2, 6, 30)) opennop_hook.hooknum = NF_BR_FORWARD; // For bridged traffic only. #else printk(KERN_ALERT "[OpenNOPDrv]: Bridged mode only supported with kernel > 2.6.30 \n"); #endif } printk(KERN_ALERT "[OpenNOPDrv]: %s \n", mode); nf_register_hook(&opennop_hook); init_timer(&daemonmonitor); daemonmonitor.expires = jiffies + (timespan * HZ); daemonmonitor.data = 0; daemonmonitor.function = daemonmonitor_function; add_timer(&daemonmonitor); return 0; } static void __exit opennopdrv_exit(void){ genl_unregister_family(&opennop_nl_family); nf_unregister_hook(&opennop_hook); del_timer_sync(&daemonmonitor); }
int irda_nl_register(void) { return genl_register_family_with_ops(&irda_nl_family, irda_nl_ops, ARRAY_SIZE(irda_nl_ops)); }
int irda_nl_register(void) { return genl_register_family_with_ops(&irda_nl_family, irda_nl_ops); }