]> git.feebdaed.xyz Git - linuxyz.git/commitdiff
secret port rm
authorseantywork <seantywork@gmail.com>
Wed, 16 Jul 2025 04:11:05 +0000 (13:11 +0900)
committerseantywork <seantywork@gmail.com>
Wed, 16 Jul 2025 04:11:05 +0000 (13:11 +0900)
secret-port/.gitignore [deleted file]
secret-port/.xyz.md [deleted file]
secret-port/knock/Makefile [deleted file]
secret-port/knock/knock.c [deleted file]
secret-port/knock/knock.h [deleted file]
secret-port/knock/main.c [deleted file]
secret-port/setup.sh [deleted file]

diff --git a/secret-port/.gitignore b/secret-port/.gitignore
deleted file mode 100644 (file)
index 386f581..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-*.out
-*.o
\ No newline at end of file
diff --git a/secret-port/.xyz.md b/secret-port/.xyz.md
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/secret-port/knock/Makefile b/secret-port/knock/Makefile
deleted file mode 100644 (file)
index cb39d5f..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-all:
-       gcc -c -o knock.o knock.c 
-
-       gcc -o portknock.out main.c knock.o 
-
-clean:
-
-       rm -rf *.out *.o
\ No newline at end of file
diff --git a/secret-port/knock/knock.c b/secret-port/knock/knock.c
deleted file mode 100644 (file)
index 0451974..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-#include "knock.h"
-
-
-void* process_rx(const int fd, char* rx_ring, int* len){
-
-    struct tpacket2_hdr* header;
-    struct pollfd                                pollset;
-    int                                                          ret;
-    char*                               off;
-
-
-
-    for (int i = 0; i < CONF_RING_FRAMES; i++){
-        // fetch a frame
-        
-        header = (void*)rx_ring + (i * FRAME_SIZE);
-        assert((((unsigned long)header) & (FRAME_SIZE - 1)) == 0);
-
-        if (header->tp_status != TP_STATUS_AVAILABLE){
-            // if none available: wait on more data
-            pollset.fd         = fd;
-            pollset.events     = POLLIN;
-            pollset.revents = 0;
-            ret                                = poll(&pollset, 1, 1 /* don't hang */);
-
-        }
-
-
-        if (header->tp_status & TP_STATUS_USER){
-
-            if (header->tp_status & TP_STATUS_COPY){
-                printf("copy\n");
-                continue;
-            }
-            *len = header->tp_len;
-
-            return (void*)header;
-        }
-    }
-    return NULL;
-}
-
-
-void process_rx_release(char* packet){
-    struct tpacket2_hdr* header = (struct tpacket2_hdr*)packet;
-    header->tp_status                                   = TP_STATUS_KERNEL;
-}
-
-void rx_flush(void* ring){
-    for (int i = 0; i < CONF_RING_FRAMES; i++){
-        struct tpacket2_hdr* hdr = ring + (i * FRAME_SIZE);
-        hdr->tp_status                                   = TP_STATUS_KERNEL;
-    }
-}
-
-
-void do_rx(){
-
-    int          status = 1;
-    char *rxRing, *pkt;
-    int          rxFd;
-    int          len;
-
-    struct sockaddr_ll txdest_daddr;
-    struct sockaddr_ll rxdest_daddr;
-
-
-    rxFd = init_packetsock(&rxRing, PACKET_RX_RING, 1, &rxdest_daddr);
-    if (rxFd < 0){
-        printf("failed to init rx packet sock\n");
-        return;
-    }
-
-    
-
-    if (bind(rxFd, (struct sockaddr*)&rxdest_daddr, sizeof(rxdest_daddr)) != 0)
-    {
-        printf("bind rxfd\n");
-        return;
-    }
-
-
-
-    int needs_flush = 0;
-    int count = 0;
-    while(1){
-
-        
-        int      offset = 0;
-        char* pkt       = NULL;
-
-
-        while (pkt = process_rx(rxFd, rxRing, &len)){
-
-            uint8_t* off = ((void*)pkt) + RX_DATA_OFFSET;
-
-            printf("server RX: %d \n", count);
-
-            view_packet(off);
-
-            printf("\n");
-
-            process_rx_release(pkt);
-
-            needs_flush = 1;
-
-            count += 1;
-            
-        }
-
-        if (needs_flush == 1){
-            rx_flush(rxRing);
-            needs_flush = 0;
-        }
-    
-    }
-
-
-
-    if (exit_packetsock(rxFd, rxRing, 1))
-        return;
-
-
-
-    return;
-}
-
diff --git a/secret-port/knock/knock.h b/secret-port/knock/knock.h
deleted file mode 100644 (file)
index 91837db..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-
-#include <stdarg.h>
-#define _GNU_SOURCE
-#define __USE_GNU
-#include <pthread.h>
-#include <sched.h>
-#include <inttypes.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-#include <unistd.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <poll.h>
-
-#include <arpa/inet.h>
-#include <netinet/if_ether.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-
-#include <linux/if.h>
-#include <linux/if_packet.h>
-#include <linux/if_ether.h>
-#include <linux/ip.h>
-
-#define CONF_RING_FRAMES 2
-#define FRAME_SIZE 2048
-#define CONF_DEVICE "veth02"
-
-
-#define SOCK_PROTOCOL(ringtype) htons(ETH_P_ALL)
-#define SOCKADDR_PROTOCOL htons(ETH_P_ALL)
-
-#define TX_DATA_OFFSET TPACKET_ALIGN(sizeof(struct tpacket2_hdr))
-#define RX_DATA_OFFSET TX_DATA_OFFSET + 34
-
-
-#define RETURN_ERROR(lvl, msg) \
-    do                         \
-    {                          \
-        fprintf(stderr, msg);  \
-        return lvl;            \
-    } while (0);
-
-
-void handle_error(const char* msg, int error);
-
-void set_affinity(int8_t cpu);
-
-void view_packet(void* packet);
-
-int init_ring_daddr(int fd, const char* ringdev, const int ringtype, struct sockaddr_ll* dest_daddr);
-
-char* init_packetsock_ring(int fd, int ringtype, int tx_mmap, struct sockaddr_ll* dest_daddr);
-
-int init_packetsock(char** ring, int ringtype, int tx_mmap, struct sockaddr_ll* dest_daddr);
-
-int exit_packetsock(int fd, char* ring, int tx_mmap);
-
-
-
-void* process_rx(const int fd, char* rx_ring, int* len);
-
-void process_rx_release(char* packet);
-
-void rx_flush(void* ring);
-
-void do_rx();
-
-
diff --git a/secret-port/knock/main.c b/secret-port/knock/main.c
deleted file mode 100644 (file)
index dd6e25c..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-#include "knock.h"
-
-
-void handle_error(const char* msg, int error){
-
-    if (error != 0){
-
-        errno = error;
-        perror(msg);
-        _exit(error);
-    }
-}
-
-void set_affinity(int8_t cpu){
-
-    cpu_set_t cpuset;
-    CPU_ZERO(&cpuset);
-    CPU_SET(cpu, &cpuset);
-
-    handle_error("pthread_set_affinity_np", pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset));
-}
-
-
-
-void view_packet(void* packet){
-
-    struct ethhdr *eth_header;
-    struct iphdr *ip_header;
-    uint8_t* data;
-    struct in_addr ip_addr;
-
-
-    eth_header = packet;
-
-    ip_header = packet + sizeof(*eth_header);
-
-    data = packet + sizeof(*eth_header) + sizeof(*ip_header);
-
-    printf("dst mac: %02x:%02x:%02x:%02x:%02x:%02x\n", 
-                eth_header->h_dest[0], 
-                eth_header->h_dest[1], 
-                eth_header->h_dest[2], 
-                eth_header->h_dest[3], 
-                eth_header->h_dest[4],
-                eth_header->h_dest[5]
-                );
-
-    ip_addr.s_addr = ntohl(ip_header->daddr);
-
-    printf("dst address: %s\n", inet_ntoa(ip_addr));
-
-    printf("data: %s\n", data);
-
-
-}
-
-int init_ring_daddr(int fd, const char* ringdev, const int ringtype, struct sockaddr_ll* dest_daddr){
-
-    struct ifreq ifr;
-    int                         ifindex;
-    struct sockaddr_ll ring_daddr;
-    // get device index
-    strcpy(ifr.ifr_name, ringdev);
-    if (ioctl(fd, SIOCGIFINDEX, &ifr))
-    {
-        perror("ioctl");
-        return -1;
-    }
-    ifindex = ifr.ifr_ifindex;
-    memset(&ring_daddr, 0, sizeof(ring_daddr));
-
-    ring_daddr.sll_family        = AF_PACKET;
-    ring_daddr.sll_protocol = SOCKADDR_PROTOCOL;
-    ring_daddr.sll_ifindex  = ifindex;
-
-
-    memcpy(dest_daddr, &ring_daddr, sizeof(dest_daddr));
-
-    return 0;
-}
-
-
-
-
-char* init_packetsock_ring(int fd, int ringtype, int tx_mmap, struct sockaddr_ll* dest_daddr){
-
-    struct tpacket_req tp;
-    char*                         ring;
-    int                                   packet_version = TPACKET_V2;
-
-    if (setsockopt(fd, SOL_PACKET, PACKET_VERSION, &packet_version, sizeof(packet_version)))
-    {
-        perror("setsockopt packet version");
-        return NULL;
-    }
-
-
-    tp.tp_block_size = FRAME_SIZE * 2;
-    tp.tp_frame_size = FRAME_SIZE;
-    tp.tp_frame_nr      = CONF_RING_FRAMES;
-    tp.tp_block_nr      = (tp.tp_frame_nr * tp.tp_frame_size) / tp.tp_block_size;
-
-
-    if (init_ring_daddr(fd, CONF_DEVICE, ringtype, dest_daddr))
-        return NULL;
-
-
-    if (ringtype == PACKET_TX_RING & !tx_mmap){
-        printf("no mmap\n");
-        return NULL;
-    }
-
-    if (setsockopt(fd, SOL_PACKET, ringtype, (void*)&tp, sizeof(tp)))
-        RETURN_ERROR(NULL, "setsockopt() ring\n");
-
-
-    // open ring
-    ring = mmap(0, tp.tp_block_size * tp.tp_block_nr, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-    if (ring == MAP_FAILED)
-        RETURN_ERROR(NULL, "mmap()\n");
-
-    return ring;
-}
-
-int init_packetsock(char** ring, int ringtype, int tx_mmap, struct sockaddr_ll* dest_daddr){
-    int fd;
-
-    fd = socket(PF_PACKET, SOCK_RAW, SOCK_PROTOCOL(ringtype));
-    if (fd < 0)
-        RETURN_ERROR(-1, "Root priliveges are required\nsocket() rx. \n");
-
-    if (ring){
-
-        *ring = init_packetsock_ring(fd, ringtype, tx_mmap, dest_daddr);
-
-        if (!tx_mmap)
-            return fd;
-
-        if (!*ring){
-
-            close(fd);
-            return -1;
-        }
-    }
-
-    return fd;
-}
-
-int exit_packetsock(int fd, char* ring, int tx_mmap){
-
-    if (tx_mmap && munmap(ring, CONF_RING_FRAMES * FRAME_SIZE)){
-        perror("munmap");
-        return 1;
-    }
-
-    if (close(fd)){
-        perror("close");
-        return 1;
-    }
-
-    return 0;
-}
-
-
-
-int main(int argc, char** argv){
-
-    printf("set affinity: 0\n");
-    set_affinity(0);
-
-    printf("using interface: %s\n", CONF_DEVICE);
-
-    do_rx();
-
-}
\ No newline at end of file
diff --git a/secret-port/setup.sh b/secret-port/setup.sh
deleted file mode 100755 (executable)
index bfa6d45..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/bash
-
-sudo ip netns add net0
-
-sudo ip link add dev veth01 type veth peer name veth02 netns net0
-
-sudo ip link set dev veth01 address 'aa:aa:aa:01:01:01'
-
-sudo ip netns exec net0 ip link set dev veth02 address 'aa:aa:aa:02:02:02'
-
-sudo ip link set up veth01
-
-sudo ip netns exec net0 ip link set up veth02
-
-sudo ip addr add 192.168.10.1/24 dev veth01
-
-sudo ip netns exec net0 ip addr add 192.168.10.2/24 dev veth02
\ No newline at end of file