All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.bechberger.ebpf.bpf.raw.ipv6hdr Maven / Gradle / Ivy

The newest version!
// Generated by jextract

package me.bechberger.ebpf.bpf.raw;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
 * {@snippet lang=c :
 * struct ipv6hdr {
 *     __u8 priority : 4;
 *     __u8 version : 4;
 *     __u8 flow_lbl[3];
 *     __be16 payload_len;
 *     __u8 nexthdr;
 *     __u8 hop_limit;
 *     union {
 *         struct {
 *             struct in6_addr saddr;
 *             struct in6_addr daddr;
 *         };
 *         struct {
 *             struct in6_addr saddr;
 *             struct in6_addr daddr;
 *         } addrs;
 *     };
 * }
 * }
 */
public class ipv6hdr {

    ipv6hdr() {
        // Should not be called directly
    }

    private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
        MemoryLayout.paddingLayout(1),
        MemoryLayout.sequenceLayout(3, Lib.C_CHAR).withName("flow_lbl"),
        Lib.C_SHORT.withName("payload_len"),
        Lib.C_CHAR.withName("nexthdr"),
        Lib.C_CHAR.withName("hop_limit"),
        MemoryLayout.unionLayout(
            MemoryLayout.structLayout(
                in6_addr.layout().withName("saddr"),
                in6_addr.layout().withName("daddr")
            ).withName("$anon$134:2"),
            ipv6hdr.addrs.layout().withName("addrs")
        ).withName("$anon$134:2")
    ).withName("ipv6hdr");

    /**
     * The layout of this struct
     */
    public static final GroupLayout layout() {
        return $LAYOUT;
    }

    private static final SequenceLayout flow_lbl$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("flow_lbl"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __u8 flow_lbl[3]
     * }
     */
    public static final SequenceLayout flow_lbl$layout() {
        return flow_lbl$LAYOUT;
    }

    private static final long flow_lbl$OFFSET = 1;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __u8 flow_lbl[3]
     * }
     */
    public static final long flow_lbl$offset() {
        return flow_lbl$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __u8 flow_lbl[3]
     * }
     */
    public static MemorySegment flow_lbl(MemorySegment struct) {
        return struct.asSlice(flow_lbl$OFFSET, flow_lbl$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __u8 flow_lbl[3]
     * }
     */
    public static void flow_lbl(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, flow_lbl$OFFSET, flow_lbl$LAYOUT.byteSize());
    }

    private static long[] flow_lbl$DIMS = { 3 };

    /**
     * Dimensions for array field:
     * {@snippet lang=c :
     * __u8 flow_lbl[3]
     * }
     */
    public static long[] flow_lbl$dimensions() {
        return flow_lbl$DIMS;
    }
    private static final VarHandle flow_lbl$ELEM_HANDLE = flow_lbl$LAYOUT.varHandle(sequenceElement());

    /**
     * Indexed getter for field:
     * {@snippet lang=c :
     * __u8 flow_lbl[3]
     * }
     */
    public static byte flow_lbl(MemorySegment struct, long index0) {
        return (byte)flow_lbl$ELEM_HANDLE.get(struct, 0L, index0);
    }

    /**
     * Indexed setter for field:
     * {@snippet lang=c :
     * __u8 flow_lbl[3]
     * }
     */
    public static void flow_lbl(MemorySegment struct, long index0, byte fieldValue) {
        flow_lbl$ELEM_HANDLE.set(struct, 0L, index0, fieldValue);
    }

    private static final OfShort payload_len$LAYOUT = (OfShort)$LAYOUT.select(groupElement("payload_len"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __be16 payload_len
     * }
     */
    public static final OfShort payload_len$layout() {
        return payload_len$LAYOUT;
    }

    private static final long payload_len$OFFSET = 4;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __be16 payload_len
     * }
     */
    public static final long payload_len$offset() {
        return payload_len$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __be16 payload_len
     * }
     */
    public static short payload_len(MemorySegment struct) {
        return struct.get(payload_len$LAYOUT, payload_len$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __be16 payload_len
     * }
     */
    public static void payload_len(MemorySegment struct, short fieldValue) {
        struct.set(payload_len$LAYOUT, payload_len$OFFSET, fieldValue);
    }

    private static final OfByte nexthdr$LAYOUT = (OfByte)$LAYOUT.select(groupElement("nexthdr"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __u8 nexthdr
     * }
     */
    public static final OfByte nexthdr$layout() {
        return nexthdr$LAYOUT;
    }

    private static final long nexthdr$OFFSET = 6;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __u8 nexthdr
     * }
     */
    public static final long nexthdr$offset() {
        return nexthdr$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __u8 nexthdr
     * }
     */
    public static byte nexthdr(MemorySegment struct) {
        return struct.get(nexthdr$LAYOUT, nexthdr$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __u8 nexthdr
     * }
     */
    public static void nexthdr(MemorySegment struct, byte fieldValue) {
        struct.set(nexthdr$LAYOUT, nexthdr$OFFSET, fieldValue);
    }

    private static final OfByte hop_limit$LAYOUT = (OfByte)$LAYOUT.select(groupElement("hop_limit"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * __u8 hop_limit
     * }
     */
    public static final OfByte hop_limit$layout() {
        return hop_limit$LAYOUT;
    }

    private static final long hop_limit$OFFSET = 7;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * __u8 hop_limit
     * }
     */
    public static final long hop_limit$offset() {
        return hop_limit$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * __u8 hop_limit
     * }
     */
    public static byte hop_limit(MemorySegment struct) {
        return struct.get(hop_limit$LAYOUT, hop_limit$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * __u8 hop_limit
     * }
     */
    public static void hop_limit(MemorySegment struct, byte fieldValue) {
        struct.set(hop_limit$LAYOUT, hop_limit$OFFSET, fieldValue);
    }

    private static final GroupLayout saddr$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$134:2"), groupElement("$anon$134:2"), groupElement("saddr"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * struct in6_addr saddr
     * }
     */
    public static final GroupLayout saddr$layout() {
        return saddr$LAYOUT;
    }

    private static final long saddr$OFFSET = 8;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * struct in6_addr saddr
     * }
     */
    public static final long saddr$offset() {
        return saddr$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * struct in6_addr saddr
     * }
     */
    public static MemorySegment saddr(MemorySegment struct) {
        return struct.asSlice(saddr$OFFSET, saddr$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * struct in6_addr saddr
     * }
     */
    public static void saddr(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, saddr$OFFSET, saddr$LAYOUT.byteSize());
    }

    private static final GroupLayout daddr$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$134:2"), groupElement("$anon$134:2"), groupElement("daddr"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * struct in6_addr daddr
     * }
     */
    public static final GroupLayout daddr$layout() {
        return daddr$LAYOUT;
    }

    private static final long daddr$OFFSET = 24;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * struct in6_addr daddr
     * }
     */
    public static final long daddr$offset() {
        return daddr$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * struct in6_addr daddr
     * }
     */
    public static MemorySegment daddr(MemorySegment struct) {
        return struct.asSlice(daddr$OFFSET, daddr$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * struct in6_addr daddr
     * }
     */
    public static void daddr(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, daddr$OFFSET, daddr$LAYOUT.byteSize());
    }

    /**
     * {@snippet lang=c :
     * struct {
     *     struct in6_addr saddr;
     *     struct in6_addr daddr;
     * }
     * }
     */
    public static class addrs {

        addrs() {
            // Should not be called directly
        }

        private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
            in6_addr.layout().withName("saddr"),
            in6_addr.layout().withName("daddr")
        ).withName("$anon$134:2");

        /**
         * The layout of this struct
         */
        public static final GroupLayout layout() {
            return $LAYOUT;
        }

        private static final GroupLayout saddr$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("saddr"));

        /**
         * Layout for field:
         * {@snippet lang=c :
         * struct in6_addr saddr
         * }
         */
        public static final GroupLayout saddr$layout() {
            return saddr$LAYOUT;
        }

        private static final long saddr$OFFSET = 0;

        /**
         * Offset for field:
         * {@snippet lang=c :
         * struct in6_addr saddr
         * }
         */
        public static final long saddr$offset() {
            return saddr$OFFSET;
        }

        /**
         * Getter for field:
         * {@snippet lang=c :
         * struct in6_addr saddr
         * }
         */
        public static MemorySegment saddr(MemorySegment struct) {
            return struct.asSlice(saddr$OFFSET, saddr$LAYOUT.byteSize());
        }

        /**
         * Setter for field:
         * {@snippet lang=c :
         * struct in6_addr saddr
         * }
         */
        public static void saddr(MemorySegment struct, MemorySegment fieldValue) {
            MemorySegment.copy(fieldValue, 0L, struct, saddr$OFFSET, saddr$LAYOUT.byteSize());
        }

        private static final GroupLayout daddr$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("daddr"));

        /**
         * Layout for field:
         * {@snippet lang=c :
         * struct in6_addr daddr
         * }
         */
        public static final GroupLayout daddr$layout() {
            return daddr$LAYOUT;
        }

        private static final long daddr$OFFSET = 16;

        /**
         * Offset for field:
         * {@snippet lang=c :
         * struct in6_addr daddr
         * }
         */
        public static final long daddr$offset() {
            return daddr$OFFSET;
        }

        /**
         * Getter for field:
         * {@snippet lang=c :
         * struct in6_addr daddr
         * }
         */
        public static MemorySegment daddr(MemorySegment struct) {
            return struct.asSlice(daddr$OFFSET, daddr$LAYOUT.byteSize());
        }

        /**
         * Setter for field:
         * {@snippet lang=c :
         * struct in6_addr daddr
         * }
         */
        public static void daddr(MemorySegment struct, MemorySegment fieldValue) {
            MemorySegment.copy(fieldValue, 0L, struct, daddr$OFFSET, daddr$LAYOUT.byteSize());
        }

        /**
         * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
         * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
         */
        public static MemorySegment asSlice(MemorySegment array, long index) {
            return array.asSlice(layout().byteSize() * index);
        }

        /**
         * The size (in bytes) of this struct
         */
        public static long sizeof() { return layout().byteSize(); }

        /**
         * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
         */
        public static MemorySegment allocate(SegmentAllocator allocator) {
            return allocator.allocate(layout());
        }

        /**
         * Allocate an array of size {@code elementCount} using {@code allocator}.
         * The returned segment has size {@code elementCount * layout().byteSize()}.
         */
        public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
            return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
        }

        /**
         * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
         * The returned segment has size {@code layout().byteSize()}
         */
        public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) {
            return reinterpret(addr, 1, arena, cleanup);
        }

        /**
         * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
         * The returned segment has size {@code elementCount * layout().byteSize()}
         */
        public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) {
            return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
        }
    }

    private static final GroupLayout addrs$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$134:2"), groupElement("addrs"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * struct {
     *     struct in6_addr saddr;
     *     struct in6_addr daddr;
     * } addrs
     * }
     */
    public static final GroupLayout addrs$layout() {
        return addrs$LAYOUT;
    }

    private static final long addrs$OFFSET = 8;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * struct {
     *     struct in6_addr saddr;
     *     struct in6_addr daddr;
     * } addrs
     * }
     */
    public static final long addrs$offset() {
        return addrs$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * struct {
     *     struct in6_addr saddr;
     *     struct in6_addr daddr;
     * } addrs
     * }
     */
    public static MemorySegment addrs(MemorySegment struct) {
        return struct.asSlice(addrs$OFFSET, addrs$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * struct {
     *     struct in6_addr saddr;
     *     struct in6_addr daddr;
     * } addrs
     * }
     */
    public static void addrs(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, addrs$OFFSET, addrs$LAYOUT.byteSize());
    }

    /**
     * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
     * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
     */
    public static MemorySegment asSlice(MemorySegment array, long index) {
        return array.asSlice(layout().byteSize() * index);
    }

    /**
     * The size (in bytes) of this struct
     */
    public static long sizeof() { return layout().byteSize(); }

    /**
     * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
     */
    public static MemorySegment allocate(SegmentAllocator allocator) {
        return allocator.allocate(layout());
    }

    /**
     * Allocate an array of size {@code elementCount} using {@code allocator}.
     * The returned segment has size {@code elementCount * layout().byteSize()}.
     */
    public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
        return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) {
        return reinterpret(addr, 1, arena, cleanup);
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code elementCount * layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) {
        return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy