Created
April 23, 2022 09:43
-
-
Save cocotyty/4f5bc48362b9e957c32ced496862aac1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* livepatch_ipvs_estimator.c - IP_VS Live Patching | |
*/ | |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
#include <linux/module.h> | |
#include <linux/kernel.h> | |
#include <linux/livepatch.h> | |
#include <net/ip_vs.h> | |
static void estimation_timer_noop(struct timer_list *t) | |
{ | |
struct netns_ipvs *ipvs = from_timer(ipvs, t, est_timer); | |
mod_timer(&ipvs->est_timer, jiffies + 600*HZ); | |
return; | |
} | |
static void livepatch_noop(struct netns_ipvs *ipvs /* $rdi */, struct ip_vs_stats *stats) | |
{ | |
return; | |
} | |
static struct klp_func funcs[] = { | |
{ | |
.old_name = "estimation_timer", | |
.new_func = estimation_timer_noop, | |
}, | |
{ | |
.old_name = "ip_vs_start_estimator", | |
.new_func = livepatch_noop, | |
}, | |
{ | |
.old_name = "ip_vs_stop_estimator", | |
.new_func = livepatch_noop, | |
}, { } | |
}; | |
static struct klp_object objs[] = { | |
{ | |
/* name being NULL means vmlinux */ | |
.name = "ip_vs", | |
.funcs = funcs, | |
}, { } | |
}; | |
static struct klp_patch patch = { | |
.mod = THIS_MODULE, | |
.objs = objs, | |
}; | |
static int livepatch_init(void) | |
{ | |
int ret; | |
ret = klp_register_patch(&patch); | |
if (ret) { | |
return ret; | |
} | |
ret = klp_enable_patch(&patch); | |
if (ret) { | |
WARN_ON(klp_unregister_patch(&patch)); | |
return ret; | |
} | |
return 0; | |
} | |
static void livepatch_exit(void) | |
{ | |
printk(KERN_INFO "ip_vs estimator patch unloaded"); | |
WARN_ON(klp_unregister_patch(&patch)); | |
} | |
module_init(livepatch_init); | |
module_exit(livepatch_exit); | |
MODULE_LICENSE("GPL"); | |
MODULE_INFO(livepatch, "Y"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Makefile