me.bechberger.ebpf.bpf.raw.iphdr Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rawbpf Show documentation
Show all versions of rawbpf Show documentation
Raw Panama bindings for libbpf generated for jextract on 64-bit Linux
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 iphdr {
* __u8 ihl : 4;
* __u8 version : 4;
* __u8 tos;
* __be16 tot_len;
* __be16 id;
* __be16 frag_off;
* __u8 ttl;
* __u8 protocol;
* __sum16 check;
* union {
* struct {
* __be32 saddr;
* __be32 daddr;
* };
* struct {
* __be32 saddr;
* __be32 daddr;
* } addrs;
* };
* }
* }
*/
public class iphdr {
iphdr() {
// Should not be called directly
}
private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
MemoryLayout.paddingLayout(1),
Lib.C_CHAR.withName("tos"),
Lib.C_SHORT.withName("tot_len"),
Lib.C_SHORT.withName("id"),
Lib.C_SHORT.withName("frag_off"),
Lib.C_CHAR.withName("ttl"),
Lib.C_CHAR.withName("protocol"),
Lib.C_SHORT.withName("check"),
MemoryLayout.unionLayout(
MemoryLayout.structLayout(
Lib.C_INT.withName("saddr"),
Lib.C_INT.withName("daddr")
).withName("$anon$104:2"),
iphdr.addrs.layout().withName("addrs")
).withName("$anon$104:2")
).withName("iphdr");
/**
* The layout of this struct
*/
public static final GroupLayout layout() {
return $LAYOUT;
}
private static final OfByte tos$LAYOUT = (OfByte)$LAYOUT.select(groupElement("tos"));
/**
* Layout for field:
* {@snippet lang=c :
* __u8 tos
* }
*/
public static final OfByte tos$layout() {
return tos$LAYOUT;
}
private static final long tos$OFFSET = 1;
/**
* Offset for field:
* {@snippet lang=c :
* __u8 tos
* }
*/
public static final long tos$offset() {
return tos$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __u8 tos
* }
*/
public static byte tos(MemorySegment struct) {
return struct.get(tos$LAYOUT, tos$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __u8 tos
* }
*/
public static void tos(MemorySegment struct, byte fieldValue) {
struct.set(tos$LAYOUT, tos$OFFSET, fieldValue);
}
private static final OfShort tot_len$LAYOUT = (OfShort)$LAYOUT.select(groupElement("tot_len"));
/**
* Layout for field:
* {@snippet lang=c :
* __be16 tot_len
* }
*/
public static final OfShort tot_len$layout() {
return tot_len$LAYOUT;
}
private static final long tot_len$OFFSET = 2;
/**
* Offset for field:
* {@snippet lang=c :
* __be16 tot_len
* }
*/
public static final long tot_len$offset() {
return tot_len$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be16 tot_len
* }
*/
public static short tot_len(MemorySegment struct) {
return struct.get(tot_len$LAYOUT, tot_len$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __be16 tot_len
* }
*/
public static void tot_len(MemorySegment struct, short fieldValue) {
struct.set(tot_len$LAYOUT, tot_len$OFFSET, fieldValue);
}
private static final OfShort id$LAYOUT = (OfShort)$LAYOUT.select(groupElement("id"));
/**
* Layout for field:
* {@snippet lang=c :
* __be16 id
* }
*/
public static final OfShort id$layout() {
return id$LAYOUT;
}
private static final long id$OFFSET = 4;
/**
* Offset for field:
* {@snippet lang=c :
* __be16 id
* }
*/
public static final long id$offset() {
return id$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be16 id
* }
*/
public static short id(MemorySegment struct) {
return struct.get(id$LAYOUT, id$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __be16 id
* }
*/
public static void id(MemorySegment struct, short fieldValue) {
struct.set(id$LAYOUT, id$OFFSET, fieldValue);
}
private static final OfShort frag_off$LAYOUT = (OfShort)$LAYOUT.select(groupElement("frag_off"));
/**
* Layout for field:
* {@snippet lang=c :
* __be16 frag_off
* }
*/
public static final OfShort frag_off$layout() {
return frag_off$LAYOUT;
}
private static final long frag_off$OFFSET = 6;
/**
* Offset for field:
* {@snippet lang=c :
* __be16 frag_off
* }
*/
public static final long frag_off$offset() {
return frag_off$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be16 frag_off
* }
*/
public static short frag_off(MemorySegment struct) {
return struct.get(frag_off$LAYOUT, frag_off$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __be16 frag_off
* }
*/
public static void frag_off(MemorySegment struct, short fieldValue) {
struct.set(frag_off$LAYOUT, frag_off$OFFSET, fieldValue);
}
private static final OfByte ttl$LAYOUT = (OfByte)$LAYOUT.select(groupElement("ttl"));
/**
* Layout for field:
* {@snippet lang=c :
* __u8 ttl
* }
*/
public static final OfByte ttl$layout() {
return ttl$LAYOUT;
}
private static final long ttl$OFFSET = 8;
/**
* Offset for field:
* {@snippet lang=c :
* __u8 ttl
* }
*/
public static final long ttl$offset() {
return ttl$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __u8 ttl
* }
*/
public static byte ttl(MemorySegment struct) {
return struct.get(ttl$LAYOUT, ttl$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __u8 ttl
* }
*/
public static void ttl(MemorySegment struct, byte fieldValue) {
struct.set(ttl$LAYOUT, ttl$OFFSET, fieldValue);
}
private static final OfByte protocol$LAYOUT = (OfByte)$LAYOUT.select(groupElement("protocol"));
/**
* Layout for field:
* {@snippet lang=c :
* __u8 protocol
* }
*/
public static final OfByte protocol$layout() {
return protocol$LAYOUT;
}
private static final long protocol$OFFSET = 9;
/**
* Offset for field:
* {@snippet lang=c :
* __u8 protocol
* }
*/
public static final long protocol$offset() {
return protocol$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __u8 protocol
* }
*/
public static byte protocol(MemorySegment struct) {
return struct.get(protocol$LAYOUT, protocol$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __u8 protocol
* }
*/
public static void protocol(MemorySegment struct, byte fieldValue) {
struct.set(protocol$LAYOUT, protocol$OFFSET, fieldValue);
}
private static final OfShort check$LAYOUT = (OfShort)$LAYOUT.select(groupElement("check"));
/**
* Layout for field:
* {@snippet lang=c :
* __sum16 check
* }
*/
public static final OfShort check$layout() {
return check$LAYOUT;
}
private static final long check$OFFSET = 10;
/**
* Offset for field:
* {@snippet lang=c :
* __sum16 check
* }
*/
public static final long check$offset() {
return check$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __sum16 check
* }
*/
public static short check(MemorySegment struct) {
return struct.get(check$LAYOUT, check$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __sum16 check
* }
*/
public static void check(MemorySegment struct, short fieldValue) {
struct.set(check$LAYOUT, check$OFFSET, fieldValue);
}
private static final OfInt saddr$LAYOUT = (OfInt)$LAYOUT.select(groupElement("$anon$104:2"), groupElement("$anon$104:2"), groupElement("saddr"));
/**
* Layout for field:
* {@snippet lang=c :
* __be32 saddr
* }
*/
public static final OfInt saddr$layout() {
return saddr$LAYOUT;
}
private static final long saddr$OFFSET = 12;
/**
* Offset for field:
* {@snippet lang=c :
* __be32 saddr
* }
*/
public static final long saddr$offset() {
return saddr$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be32 saddr
* }
*/
public static int saddr(MemorySegment struct) {
return struct.get(saddr$LAYOUT, saddr$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __be32 saddr
* }
*/
public static void saddr(MemorySegment struct, int fieldValue) {
struct.set(saddr$LAYOUT, saddr$OFFSET, fieldValue);
}
private static final OfInt daddr$LAYOUT = (OfInt)$LAYOUT.select(groupElement("$anon$104:2"), groupElement("$anon$104:2"), groupElement("daddr"));
/**
* Layout for field:
* {@snippet lang=c :
* __be32 daddr
* }
*/
public static final OfInt daddr$layout() {
return daddr$LAYOUT;
}
private static final long daddr$OFFSET = 16;
/**
* Offset for field:
* {@snippet lang=c :
* __be32 daddr
* }
*/
public static final long daddr$offset() {
return daddr$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be32 daddr
* }
*/
public static int daddr(MemorySegment struct) {
return struct.get(daddr$LAYOUT, daddr$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __be32 daddr
* }
*/
public static void daddr(MemorySegment struct, int fieldValue) {
struct.set(daddr$LAYOUT, daddr$OFFSET, fieldValue);
}
/**
* {@snippet lang=c :
* struct {
* __be32 saddr;
* __be32 daddr;
* }
* }
*/
public static class addrs {
addrs() {
// Should not be called directly
}
private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
Lib.C_INT.withName("saddr"),
Lib.C_INT.withName("daddr")
).withName("$anon$104:2");
/**
* The layout of this struct
*/
public static final GroupLayout layout() {
return $LAYOUT;
}
private static final OfInt saddr$LAYOUT = (OfInt)$LAYOUT.select(groupElement("saddr"));
/**
* Layout for field:
* {@snippet lang=c :
* __be32 saddr
* }
*/
public static final OfInt saddr$layout() {
return saddr$LAYOUT;
}
private static final long saddr$OFFSET = 0;
/**
* Offset for field:
* {@snippet lang=c :
* __be32 saddr
* }
*/
public static final long saddr$offset() {
return saddr$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be32 saddr
* }
*/
public static int saddr(MemorySegment struct) {
return struct.get(saddr$LAYOUT, saddr$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __be32 saddr
* }
*/
public static void saddr(MemorySegment struct, int fieldValue) {
struct.set(saddr$LAYOUT, saddr$OFFSET, fieldValue);
}
private static final OfInt daddr$LAYOUT = (OfInt)$LAYOUT.select(groupElement("daddr"));
/**
* Layout for field:
* {@snippet lang=c :
* __be32 daddr
* }
*/
public static final OfInt daddr$layout() {
return daddr$LAYOUT;
}
private static final long daddr$OFFSET = 4;
/**
* Offset for field:
* {@snippet lang=c :
* __be32 daddr
* }
*/
public static final long daddr$offset() {
return daddr$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be32 daddr
* }
*/
public static int daddr(MemorySegment struct) {
return struct.get(daddr$LAYOUT, daddr$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __be32 daddr
* }
*/
public static void daddr(MemorySegment struct, int fieldValue) {
struct.set(daddr$LAYOUT, daddr$OFFSET, fieldValue);
}
/**
* 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$104:2"), groupElement("addrs"));
/**
* Layout for field:
* {@snippet lang=c :
* struct {
* __be32 saddr;
* __be32 daddr;
* } addrs
* }
*/
public static final GroupLayout addrs$layout() {
return addrs$LAYOUT;
}
private static final long addrs$OFFSET = 12;
/**
* Offset for field:
* {@snippet lang=c :
* struct {
* __be32 saddr;
* __be32 daddr;
* } addrs
* }
*/
public static final long addrs$offset() {
return addrs$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* struct {
* __be32 saddr;
* __be32 daddr;
* } addrs
* }
*/
public static MemorySegment addrs(MemorySegment struct) {
return struct.asSlice(addrs$OFFSET, addrs$LAYOUT.byteSize());
}
/**
* Setter for field:
* {@snippet lang=c :
* struct {
* __be32 saddr;
* __be32 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);
}
}