Skip to content

Instantly share code, notes, and snippets.

@cocotyty
Created April 23, 2022 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocotyty/4f5bc48362b9e957c32ced496862aac1 to your computer and use it in GitHub Desktop.
Save cocotyty/4f5bc48362b9e957c32ced496862aac1 to your computer and use it in GitHub Desktop.
/*
* 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");
@cocotyty
Copy link
Author

Makefile

obj-m := livepatch_ipvs_estimator.o
patch-objs += livepatch_ipvs_estimator.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment