Skip to content

Instantly share code, notes, and snippets.

View gamemann's full-sized avatar

Christian Deacon gamemann

View GitHub Profile
@gamemann
gamemann / TestServerv2.c
Created March 2, 2020 03:17
Altered version of TestServer.c.
/* Testing forwarding packets to destination. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/if_packet.h>
@gamemann
gamemann / test_veth.c
Created March 19, 2020 14:24
Testing sending outbound packets inside network namespace via AF_PACKET sockets
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <linux/if.h>
@gamemann
gamemann / xdp-payload-match.c
Last active May 8, 2020 13:47
Payload matching attempt via goto.
// Payload match.
if (filter[i]->payloadLen > 0)
{
// Initialize packet data.
for (uint16_t j = 0; j < MAX_PCKT_LENGTH; j++)
{
if ((j + 1) > filter[i]->payloadLen)
{
break;
}
@gamemann
gamemann / udp_stress.c
Last active December 4, 2020 19:24
Program I made to get the most out of sending packets via Linux sockets. Was able to push 24 gbps at 61 bytes per packet with an older Intel Xeon.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sysinfo.h>
#include <netinet/in.h>
#include <net/if.h>
#include <linux/if.h>
#include <linux/if_ether.h>
@gamemann
gamemann / xdp_bpf_maps.c
Created December 16, 2020 14:49
Small XDP program that stores IP and ICMP headers into a per-CPU map and prints out data later on. Not sure how well storing these in a per-CPU map will do in regards to performance.
#include <linux/bpf.h>
#include <linux/bpf_common.h>
#include <inttypes.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/icmp.h>
#include <linux/in.h>
#include "/home/dev/XDP-Firewall/libbpf/src/bpf_helpers.h"
@gamemann
gamemann / xdp_fw_ipv6.c
Created December 16, 2020 15:06
XDP IPv6 support #1.
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/udp.h>
#include <linux/tcp.h>
#include <linux/icmp.h>
#include <linux/icmpv6.h>
#include <linux/in.h>
#include <inttypes.h>
#include <stdint.h>
@gamemann
gamemann / xdp_fw_ipv6_maps.c
Last active December 16, 2020 15:19
XDP FW trying to implement IPv6 support with BPF maps.
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/udp.h>
#include <linux/tcp.h>
#include <linux/icmp.h>
#include <linux/icmpv6.h>
#include <linux/in.h>
#include <inttypes.h>
#include <stdint.h>
@gamemann
gamemann / ipv6_send.c
Created December 18, 2020 03:39
Small C program I made to send empty UDP packets per second over IPv6.
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/if_ether.h>
#include <linux/ipv6.h>
#include <linux/udp.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <net/if.h>
@gamemann
gamemann / matrix.md
Last active August 2, 2023 22:06
Matrix Linux Command

Linux command that outputs code animations similar to the movie The Matrix.

while :; do \
    echo \
        $LINES \
        $COLUMNS \
        $(( $RANDOM % $COLUMNS)) \
        $(printf "\U$(($RANDOM % 500))"); \
 sleep 0.05; \
@gamemann
gamemann / TestServer.c
Last active December 22, 2023 06:58
A test server that receives ethernet IP packets and uses epoll() to check when the socket is ready to read. Also supports multi-threading via `pthreads`.
/* Testing forwarding packets to destination. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/if_packet.h>