Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@DRiKE
DRiKE / xdp1-7-dns_says_no_final.c
Created July 16, 2020 18:35
XDP blog, post 1 gist 7
static __always_inline
void csum_remove_data(uint32_t *csum, struct cursor *c, uint16_t len)
{
if (c->pos + len <= c->end) {
*csum = bpf_csum_diff(c->pos, len, 0, 0, *csum);
c->pos += len;
}
}
int xdp_dns_says_no(struct xdp_md *ctx)
@DRiKE
DRiKE / xdp1-6-udp_dns_reply-part2.c
Created July 16, 2020 18:34
XDP blog, post 1 gist 6
// continuing:
if (dns->arcount) {
struct dns_rr *opt_rr;
uint8_t *opt_owner = c->pos;
opt_owner = c->pos;
if (++c->pos > c->end || *opt_owner
|| !(opt_rr = parse_dns_rr(c))
|| opt_rr->type != __bpf_htons(RR_TYPE_OPT))
@DRiKE
DRiKE / xdp1-5-udp_dns_reply.c
Last active July 16, 2020 18:33
XDP blog, post 1 gist 5
static __always_inline
int udp_dns_reply(struct cursor *c)
{
struct udphdr *udp;
struct dnshdr *dns;
if (!(udp = parse_udphdr(c))|| udp->dest != __bpf_htons(DNS_PORT)
|| !(dns = parse_dnshdr(c)))
return -1;
@DRiKE
DRiKE / xdp1-4-dns_qrr.c
Created July 16, 2020 18:29
XDP blog, post 1 gist 4
struct dns_qrr {
uint16_t qtype;
uint16_t qclass;
};
struct dns_rr {
uint16_t type;
uint16_t class;
uint32_t ttl;
uint16_t rdata_len;
@DRiKE
DRiKE / xdpblog1-3-parse_dname.c
Created July 16, 2020 18:28
XDP blog, post 1 gist 3
static __always_inline
uint8_t *parse_dname(struct cursor *c, uint8_t *pkt)
{
uint8_t *dname = c->pos;
int i;
for (i = 0; i < 128; i++) { /* Maximum 128 labels */
uint8_t o;
if (c->pos + 1 > c->end)
@DRiKE
DRiKE / xdpblog1-2-dnshdr.c
Created July 16, 2020 14:08
XDP blog, post 1 gist 2
struct dnshdr {
uint16_t id;
union {
struct {
uint8_t rd : 1;
uint8_t tc : 1;
uint8_t aa : 1;
uint8_t opcode : 4;
uint8_t qr : 1;
@DRiKE
DRiKE / xdpblog1-1_xdp_dns_says_no.c
Created July 16, 2020 13:47
XDP blog, post 1 gist 1
SEC("xdp-dns-says-no-v1")
int xdp_dns_says_no(struct xdp_md *ctx)
{
struct cursor c;
struct ethhdr *eth;
uint16_t eth_proto;
struct iphdr *ipv4;
struct ipv6hdr *ipv6;
cursor_init(&c, ctx);
@DRiKE
DRiKE / goldencheetah-3.5.1710.ebuild
Created December 24, 2017 11:11
GoldenCheetah Gentoo ebuild, v3.5-DEV1710
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
EAPI=6
inherit qmake-utils
inherit versionator
MY_PN="GoldenCheetah"
MY_PV=$(replace_version_separator 2 '-DEV')
@DRiKE
DRiKE / fastbike_avoid_unpaved_gravel.brf
Last active August 29, 2023 13:34
brouter fastbike avoiding unpaved/gravel at all cost
#
# A fastbike could be a racing bike or a speed pedelec.
# But also at night or in rainy whether you might want
# to fallback to this one.
#
# Structure is similar to trekking.brf, see this for documenation.
#
---context:global # following code refers to global config
@DRiKE
DRiKE / simplesix.c
Created November 5, 2015 20:22
Minimal example of extracting the IPv6 Flow Label from IPv6 packets
#include <stdio.h>
#include <pcap.h>
#include <arpa/inet.h>
#include <linux/if_ether.h>
#include <netinet/ip6.h>
#define SNAP_LEN 1500
int main(int argc, char *argv[]) {