Re: How to get system localtime/wall time from eBPF?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 21, 2023 at 10:43 AM Toke Høiland-Jørgensen <toke@xxxxxxxxxx> wrote:
>
> Vincent Li <vincent.mc.li@xxxxxxxxx> writes:
>
> > On Mon, Mar 20, 2023 at 2:57 PM Vincent Li <vincent.mc.li@xxxxxxxxx> wrote:
> >>
> >> On Mon, Mar 20, 2023 at 10:15 AM Jesper Dangaard Brouer
> >> <jbrouer@xxxxxxxxxx> wrote:
> >> >
> >> >
> >> > On 20/03/2023 16.33, Vincent Li wrote:
> >> > >
> >> > > if I have a XDP based firewall to block ip  access based on system
> >> > > localtime/wall time, is it still impossible like what mentioned here
> >> > > https://github.com/xdp-project/xdp-tutorial/issues/204#issuecomment-819419800?
> >> > > If so, is there any way to workaround this?
> >> >
> >> > You could use the BPF-helper named: bpf_ktime_get_tai_ns()
> >> >
> >> > See man clock_gettime(2). It is the same as CLOCK_TAI, which is
> >> > (currently) offset with 37 sec to CLOCK_REALTIME which is wall-clock.
> >> >
> >
> > sorry a follow-up question, the bpf_ktime_get_tai_ns will return time
> > as nano seconds, right?
> > I do not need the nanoseconds precision, I only need HH:MM like hours
> > and minutes of the day, for example 10:30 = 10 * 60 + 30 is good
> > enough,
> >  any trick get that from bpf_ktime_get_tai_ns()
>
> Populate the time at latest midnight from userspace when installing the
> program and calculate offsets from that?
>

Yes, I populated the map with 10 * 60 + 30 from user space, the
remaining question is how to get minutes of the day from
bpf_ktime_get_tai_ns(), I guess that is what you mean to calculate the
offsets from kernel bpf code?




[Index of Archives]     [Linux Networking Development]     [Fedora Linux Users]     [Linux SCTP]     [DCCP]     [Gimp]     [Yosemite Campsites]

  Powered by Linux