Skip to content

Instantly share code, notes, and snippets.

@lrita
Created June 28, 2018 02:57
Show Gist options
  • Save lrita/0fcb5750b6cc04f29528c9dfad79066c to your computer and use it in GitHub Desktop.
Save lrita/0fcb5750b6cc04f29528c9dfad79066c to your computer and use it in GitHub Desktop.
# stap -g inject_accept.stp $pid
%{
#include <net/sock.h>
%}
function set_sock_keepalive:long(fd) %{
int err = -1;
int keepalive = 1;
struct socket *sock = sockfd_lookup(STAP_ARG_fd, &err);
if (sock != NULL) {
mm_segment_t oldfs;
oldfs = get_fs();
set_fs(KERNEL_DS);
err = sock_setsockopt(sock, SOL_SOCKET,
SO_KEEPALIVE, (char __user*)&keepalive, sizeof(keepalive));
set_fs(oldfs);
sockfd_put(sock);
}
STAP_RETURN(err);
%}
probe begin {
printf("inject begin... \n")
}
probe syscall.accept.return, syscall.accept4.return {
# 当进程号为脚本后第一个参数时,注入keepalive
fd = $return
if ((pid() == $1) && (fd != -1)) {
ok = set_sock_keepalive(fd)
if (ok)
printf("set_sock_keepalive %d\n", ok)
}
}
probe end {
printf("inject end... \n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment