| #include <linux/sysctl.h> |
| #include <linux/slab.h> |
| #include <net/net_namespace.h> |
| #include <net/xfrm.h> |
| |
| static void __net_init __xfrm_sysctl_init(struct net *net) |
| { |
| net->xfrm.sysctl_aevent_etime = XFRM_AE_ETIME; |
| net->xfrm.sysctl_aevent_rseqth = XFRM_AE_SEQT_SIZE; |
| net->xfrm.sysctl_larval_drop = 1; |
| net->xfrm.sysctl_acq_expires = 30; |
| |
| // cradlepoint |
| net->xfrm.total_packets = 0; |
| net->xfrm.total_bytes = 0; |
| } |
| |
| #ifdef CONFIG_SYSCTL |
| |
| // cradlepoint |
| int proc_total_stats(struct ctl_table *table, int write, |
| void __user *buffer, size_t *lenp, loff_t *ppos) |
| { |
| u64 val; |
| int ret; |
| unsigned int seq; |
| seqlock_t *lock = &((struct net*)table->extra1)->xfrm.xfrm_total_stats_lock; |
| |
| if (write) |
| return -EPERM; |
| |
| do { |
| seq = read_seqbegin(lock); |
| val = *(u64 *)(table->extra2); |
| } while (read_seqretry(lock, seq)); |
| |
| table->data = kmalloc(table->maxlen, GFP_USER); |
| if (!table->data) |
| return -ENOMEM; |
| |
| snprintf((char*)(table->data), table->maxlen, "%llu", val); |
| |
| ret = proc_dostring(table, write, buffer, lenp, ppos); |
| |
| kfree(table->data); |
| |
| return ret; |
| } |
| |
| static struct ctl_table xfrm_table[] = { |
| { |
| .procname = "xfrm_aevent_etime", |
| .maxlen = sizeof(u32), |
| .mode = 0644, |
| .proc_handler = proc_dointvec |
| }, |
| { |
| .procname = "xfrm_aevent_rseqth", |
| .maxlen = sizeof(u32), |
| .mode = 0644, |
| .proc_handler = proc_dointvec |
| }, |
| { |
| .procname = "xfrm_larval_drop", |
| .maxlen = sizeof(int), |
| .mode = 0644, |
| .proc_handler = proc_dointvec |
| }, |
| { |
| .procname = "xfrm_acq_expires", |
| .maxlen = sizeof(int), |
| .mode = 0644, |
| .proc_handler = proc_dointvec |
| }, |
| { |
| /* cradlepoint */ |
| .procname = "xfrm_total_packets", |
| .maxlen = 256, |
| .mode = 0644, |
| .proc_handler = proc_total_stats |
| }, |
| { |
| /* cradlepoint */ |
| .procname = "xfrm_total_bytes", |
| .maxlen = 256, |
| .mode = 0644, |
| .proc_handler = proc_total_stats |
| }, |
| {} |
| }; |
| |
| int __net_init xfrm_sysctl_init(struct net *net) |
| { |
| struct ctl_table *table; |
| |
| __xfrm_sysctl_init(net); |
| |
| table = kmemdup(xfrm_table, sizeof(xfrm_table), GFP_KERNEL); |
| if (!table) |
| goto out_kmemdup; |
| table[0].data = &net->xfrm.sysctl_aevent_etime; |
| table[1].data = &net->xfrm.sysctl_aevent_rseqth; |
| table[2].data = &net->xfrm.sysctl_larval_drop; |
| table[3].data = &net->xfrm.sysctl_acq_expires; |
| |
| // cradlepoint xfrm total counters |
| table[4].extra1 = (void*) net; |
| table[4].extra2 = &net->xfrm.total_packets; |
| table[5].extra1 = (void*) net; |
| table[5].extra2 = &net->xfrm.total_bytes; |
| |
| /* Don't export sysctls to unprivileged users */ |
| if (net->user_ns != &init_user_ns) |
| table[0].procname = NULL; |
| |
| net->xfrm.sysctl_hdr = register_net_sysctl(net, "net/core", table); |
| if (!net->xfrm.sysctl_hdr) |
| goto out_register; |
| return 0; |
| |
| out_register: |
| kfree(table); |
| out_kmemdup: |
| return -ENOMEM; |
| } |
| |
| void __net_exit xfrm_sysctl_fini(struct net *net) |
| { |
| struct ctl_table *table; |
| |
| table = net->xfrm.sysctl_hdr->ctl_table_arg; |
| unregister_net_sysctl_table(net->xfrm.sysctl_hdr); |
| kfree(table); |
| } |
| #else |
| int __net_init xfrm_sysctl_init(struct net *net) |
| { |
| __xfrm_sysctl_init(net); |
| return 0; |
| } |
| #endif |