というのは出来ないっぽい。

linux には ip token set ::35 dev eth0 というのがあるようだ。
https://wiki.gentoo.org/wiki/IPv6_Static_Addresses_using_Tokens

prefixの変更をフックしたいのだけれど、定期的に見にいくしかないのかな。。。

とりあえずIPが変更されたときにログに吐くkmod。rsyslogやswatch的なやつで。ip moniterとか使えるのかなぁ。。。

Makefile
.PATH: ${SRCTOP}/sys/libkern

KMOD=log_ifaddr_event

SRCS+=log_ifaddr_event.c
SRCS+=inet_ntop.c

.include <bsd.kmod.mk>
log_ifaddr_event.c
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/conf.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_var.h>
#include <netinet/in.h>
#include <netdb.h>

static void
log_ifaddr_event_hook(void *arg, struct ifnet *ifp, struct ifaddr *ia_ifa, int add_or_del)
{
    char addr_buf[NI_MAXHOST];

    if (ia_ifa->ifa_addr->sa_family == AF_INET) {
        inet_ntop(AF_INET,  &((struct sockaddr_in  *)ia_ifa->ifa_addr)->sin_addr,  addr_buf, sizeof(addr_buf));
        printf("log_ifaddr_event.ko ifaddr_event %s %s %s \n", ifp->if_xname, addr_buf, add_or_del ? "DEL" : "ADD");
    }
    else if (ia_ifa->ifa_addr->sa_family == AF_INET6) {
        inet_ntop(AF_INET6, &((struct sockaddr_in6 *)ia_ifa->ifa_addr)->sin6_addr, addr_buf, sizeof(addr_buf));
        printf("log_ifaddr_event.ko ifaddr_event %s %s %s \n", ifp->if_xname, addr_buf, add_or_del ? "DEL" : "ADD");
    }

    return;
}

static int
module_load(module_t mod, int cmd, void *arg)
{
    static eventhandler_tag tag;
    switch (cmd) {
        case MOD_LOAD:
            printf("log_ifaddr_event.ko loaded.\n");
            tag = EVENTHANDLER_REGISTER(ifaddr_event_ext, log_ifaddr_event_hook, 0, EVENTHANDLER_PRI_ANY);
            if (tag == NULL) {
                printf("log_ifaddr_event.ko EVENTHANDLER_REGISTER failed.\n");
            }
            else {
                printf("log_ifaddr_event.ko EVENTHANDLER_REGISTER successed.\n");
            }
            break;
        case MOD_UNLOAD:
            if (tag != NULL) {
                EVENTHANDLER_DEREGISTER(ifaddr_event_ext, tag);
                printf("log_ifaddr_event.ko EVENTHANDLER_DEREGISTER done.\n");
            }
            printf("log_ifaddr_event.ko unloaded.\n");
            break;
        default:
            return EOPNOTSUPP;
    }

    return 0;
}

DEV_MODULE(log_ifaddr_event, module_load, NULL);
/var/log/message
May 16 18:49:54 host100 kernel: log_ifaddr_event.ko loaded.
May 16 18:49:54 host100 kernel: log_ifaddr_event.ko EVENTHANDLER_REGISTER successed.
May 16 18:50:04 host100 kernel: log_ifaddr_event.ko ifaddr_event igb0 24XX:XX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX DEL
May 16 18:50:13 host100 kernel: log_ifaddr_event.ko ifaddr_event igb0 192.168.1.XXX ADD
May 16 18:50:15 host100 kernel: log_ifaddr_event.ko ifaddr_event igb0 192.168.1.XXX DEL
May 16 18:50:19 host100 kernel: log_ifaddr_event.ko EVENTHANDLER_DEREGISTER done.
May 16 18:50:19 host100 kernel: log_ifaddr_event.ko unloaded.

コメントする

perl adv
perl adv