me.bechberger.ebpf.bpf.raw.bpf_sock_tuple 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 bpf_sock_tuple {
* union {
* struct {
* __be32 saddr;
* __be32 daddr;
* __be16 sport;
* __be16 dport;
* } ipv4;
* struct {
* __be32 saddr[4];
* __be32 daddr[4];
* __be16 sport;
* __be16 dport;
* } ipv6;
* };
* }
* }
*/
public class bpf_sock_tuple {
bpf_sock_tuple() {
// Should not be called directly
}
private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
MemoryLayout.unionLayout(
bpf_sock_tuple.ipv4.layout().withName("ipv4"),
bpf_sock_tuple.ipv6.layout().withName("ipv6")
).withName("$anon$6391:2")
).withName("bpf_sock_tuple");
/**
* The layout of this struct
*/
public static final GroupLayout layout() {
return $LAYOUT;
}
/**
* {@snippet lang=c :
* struct {
* __be32 saddr;
* __be32 daddr;
* __be16 sport;
* __be16 dport;
* }
* }
*/
public static class ipv4 {
ipv4() {
// Should not be called directly
}
private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
Lib.C_INT.withName("saddr"),
Lib.C_INT.withName("daddr"),
Lib.C_SHORT.withName("sport"),
Lib.C_SHORT.withName("dport")
).withName("$anon$6392:3");
/**
* 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);
}
private static final OfShort sport$LAYOUT = (OfShort)$LAYOUT.select(groupElement("sport"));
/**
* Layout for field:
* {@snippet lang=c :
* __be16 sport
* }
*/
public static final OfShort sport$layout() {
return sport$LAYOUT;
}
private static final long sport$OFFSET = 8;
/**
* Offset for field:
* {@snippet lang=c :
* __be16 sport
* }
*/
public static final long sport$offset() {
return sport$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be16 sport
* }
*/
public static short sport(MemorySegment struct) {
return struct.get(sport$LAYOUT, sport$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __be16 sport
* }
*/
public static void sport(MemorySegment struct, short fieldValue) {
struct.set(sport$LAYOUT, sport$OFFSET, fieldValue);
}
private static final OfShort dport$LAYOUT = (OfShort)$LAYOUT.select(groupElement("dport"));
/**
* Layout for field:
* {@snippet lang=c :
* __be16 dport
* }
*/
public static final OfShort dport$layout() {
return dport$LAYOUT;
}
private static final long dport$OFFSET = 10;
/**
* Offset for field:
* {@snippet lang=c :
* __be16 dport
* }
*/
public static final long dport$offset() {
return dport$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be16 dport
* }
*/
public static short dport(MemorySegment struct) {
return struct.get(dport$LAYOUT, dport$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __be16 dport
* }
*/
public static void dport(MemorySegment struct, short fieldValue) {
struct.set(dport$LAYOUT, dport$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 ipv4$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$6391:2"), groupElement("ipv4"));
/**
* Layout for field:
* {@snippet lang=c :
* struct {
* __be32 saddr;
* __be32 daddr;
* __be16 sport;
* __be16 dport;
* } ipv4
* }
*/
public static final GroupLayout ipv4$layout() {
return ipv4$LAYOUT;
}
private static final long ipv4$OFFSET = 0;
/**
* Offset for field:
* {@snippet lang=c :
* struct {
* __be32 saddr;
* __be32 daddr;
* __be16 sport;
* __be16 dport;
* } ipv4
* }
*/
public static final long ipv4$offset() {
return ipv4$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* struct {
* __be32 saddr;
* __be32 daddr;
* __be16 sport;
* __be16 dport;
* } ipv4
* }
*/
public static MemorySegment ipv4(MemorySegment struct) {
return struct.asSlice(ipv4$OFFSET, ipv4$LAYOUT.byteSize());
}
/**
* Setter for field:
* {@snippet lang=c :
* struct {
* __be32 saddr;
* __be32 daddr;
* __be16 sport;
* __be16 dport;
* } ipv4
* }
*/
public static void ipv4(MemorySegment struct, MemorySegment fieldValue) {
MemorySegment.copy(fieldValue, 0L, struct, ipv4$OFFSET, ipv4$LAYOUT.byteSize());
}
/**
* {@snippet lang=c :
* struct {
* __be32 saddr[4];
* __be32 daddr[4];
* __be16 sport;
* __be16 dport;
* }
* }
*/
public static class ipv6 {
ipv6() {
// Should not be called directly
}
private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
MemoryLayout.sequenceLayout(4, Lib.C_INT).withName("saddr"),
MemoryLayout.sequenceLayout(4, Lib.C_INT).withName("daddr"),
Lib.C_SHORT.withName("sport"),
Lib.C_SHORT.withName("dport")
).withName("$anon$6398:3");
/**
* The layout of this struct
*/
public static final GroupLayout layout() {
return $LAYOUT;
}
private static final SequenceLayout saddr$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("saddr"));
/**
* Layout for field:
* {@snippet lang=c :
* __be32 saddr[4]
* }
*/
public static final SequenceLayout saddr$layout() {
return saddr$LAYOUT;
}
private static final long saddr$OFFSET = 0;
/**
* Offset for field:
* {@snippet lang=c :
* __be32 saddr[4]
* }
*/
public static final long saddr$offset() {
return saddr$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be32 saddr[4]
* }
*/
public static MemorySegment saddr(MemorySegment struct) {
return struct.asSlice(saddr$OFFSET, saddr$LAYOUT.byteSize());
}
/**
* Setter for field:
* {@snippet lang=c :
* __be32 saddr[4]
* }
*/
public static void saddr(MemorySegment struct, MemorySegment fieldValue) {
MemorySegment.copy(fieldValue, 0L, struct, saddr$OFFSET, saddr$LAYOUT.byteSize());
}
private static long[] saddr$DIMS = { 4 };
/**
* Dimensions for array field:
* {@snippet lang=c :
* __be32 saddr[4]
* }
*/
public static long[] saddr$dimensions() {
return saddr$DIMS;
}
private static final VarHandle saddr$ELEM_HANDLE = saddr$LAYOUT.varHandle(sequenceElement());
/**
* Indexed getter for field:
* {@snippet lang=c :
* __be32 saddr[4]
* }
*/
public static int saddr(MemorySegment struct, long index0) {
return (int)saddr$ELEM_HANDLE.get(struct, 0L, index0);
}
/**
* Indexed setter for field:
* {@snippet lang=c :
* __be32 saddr[4]
* }
*/
public static void saddr(MemorySegment struct, long index0, int fieldValue) {
saddr$ELEM_HANDLE.set(struct, 0L, index0, fieldValue);
}
private static final SequenceLayout daddr$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("daddr"));
/**
* Layout for field:
* {@snippet lang=c :
* __be32 daddr[4]
* }
*/
public static final SequenceLayout daddr$layout() {
return daddr$LAYOUT;
}
private static final long daddr$OFFSET = 16;
/**
* Offset for field:
* {@snippet lang=c :
* __be32 daddr[4]
* }
*/
public static final long daddr$offset() {
return daddr$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be32 daddr[4]
* }
*/
public static MemorySegment daddr(MemorySegment struct) {
return struct.asSlice(daddr$OFFSET, daddr$LAYOUT.byteSize());
}
/**
* Setter for field:
* {@snippet lang=c :
* __be32 daddr[4]
* }
*/
public static void daddr(MemorySegment struct, MemorySegment fieldValue) {
MemorySegment.copy(fieldValue, 0L, struct, daddr$OFFSET, daddr$LAYOUT.byteSize());
}
private static long[] daddr$DIMS = { 4 };
/**
* Dimensions for array field:
* {@snippet lang=c :
* __be32 daddr[4]
* }
*/
public static long[] daddr$dimensions() {
return daddr$DIMS;
}
private static final VarHandle daddr$ELEM_HANDLE = daddr$LAYOUT.varHandle(sequenceElement());
/**
* Indexed getter for field:
* {@snippet lang=c :
* __be32 daddr[4]
* }
*/
public static int daddr(MemorySegment struct, long index0) {
return (int)daddr$ELEM_HANDLE.get(struct, 0L, index0);
}
/**
* Indexed setter for field:
* {@snippet lang=c :
* __be32 daddr[4]
* }
*/
public static void daddr(MemorySegment struct, long index0, int fieldValue) {
daddr$ELEM_HANDLE.set(struct, 0L, index0, fieldValue);
}
private static final OfShort sport$LAYOUT = (OfShort)$LAYOUT.select(groupElement("sport"));
/**
* Layout for field:
* {@snippet lang=c :
* __be16 sport
* }
*/
public static final OfShort sport$layout() {
return sport$LAYOUT;
}
private static final long sport$OFFSET = 32;
/**
* Offset for field:
* {@snippet lang=c :
* __be16 sport
* }
*/
public static final long sport$offset() {
return sport$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be16 sport
* }
*/
public static short sport(MemorySegment struct) {
return struct.get(sport$LAYOUT, sport$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __be16 sport
* }
*/
public static void sport(MemorySegment struct, short fieldValue) {
struct.set(sport$LAYOUT, sport$OFFSET, fieldValue);
}
private static final OfShort dport$LAYOUT = (OfShort)$LAYOUT.select(groupElement("dport"));
/**
* Layout for field:
* {@snippet lang=c :
* __be16 dport
* }
*/
public static final OfShort dport$layout() {
return dport$LAYOUT;
}
private static final long dport$OFFSET = 34;
/**
* Offset for field:
* {@snippet lang=c :
* __be16 dport
* }
*/
public static final long dport$offset() {
return dport$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* __be16 dport
* }
*/
public static short dport(MemorySegment struct) {
return struct.get(dport$LAYOUT, dport$OFFSET);
}
/**
* Setter for field:
* {@snippet lang=c :
* __be16 dport
* }
*/
public static void dport(MemorySegment struct, short fieldValue) {
struct.set(dport$LAYOUT, dport$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 ipv6$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$6391:2"), groupElement("ipv6"));
/**
* Layout for field:
* {@snippet lang=c :
* struct {
* __be32 saddr[4];
* __be32 daddr[4];
* __be16 sport;
* __be16 dport;
* } ipv6
* }
*/
public static final GroupLayout ipv6$layout() {
return ipv6$LAYOUT;
}
private static final long ipv6$OFFSET = 0;
/**
* Offset for field:
* {@snippet lang=c :
* struct {
* __be32 saddr[4];
* __be32 daddr[4];
* __be16 sport;
* __be16 dport;
* } ipv6
* }
*/
public static final long ipv6$offset() {
return ipv6$OFFSET;
}
/**
* Getter for field:
* {@snippet lang=c :
* struct {
* __be32 saddr[4];
* __be32 daddr[4];
* __be16 sport;
* __be16 dport;
* } ipv6
* }
*/
public static MemorySegment ipv6(MemorySegment struct) {
return struct.asSlice(ipv6$OFFSET, ipv6$LAYOUT.byteSize());
}
/**
* Setter for field:
* {@snippet lang=c :
* struct {
* __be32 saddr[4];
* __be32 daddr[4];
* __be16 sport;
* __be16 dport;
* } ipv6
* }
*/
public static void ipv6(MemorySegment struct, MemorySegment fieldValue) {
MemorySegment.copy(fieldValue, 0L, struct, ipv6$OFFSET, ipv6$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);
}
}