Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
sudo apt-get install -y clang-format
- name: Run clang-format
run: |
clang-format --dry-run --Werror src/*.c
clang-format --dry-run --Werror src/*.c include/*.h

Build:
name: Build
Expand Down Expand Up @@ -130,9 +130,9 @@ jobs:
VERSION="${{ inputs.version }}"

if [ -n "$VERSION" ]; then
make STATIC=1 CROSS_PREFIX="$CROSS_PREFIX" VERSION="$VERSION"
make -j$(nproc) CFLAGS="-Werror" STATIC=1 CROSS_PREFIX="$CROSS_PREFIX" VERSION="$VERSION"
else
make STATIC=1 CROSS_PREFIX="$CROSS_PREFIX"
make -j$(nproc) CFLAGS="-Werror" STATIC=1 CROSS_PREFIX="$CROSS_PREFIX"
fi
- name: Upload ${{ matrix.name }}
uses: actions/upload-artifact@v4
Expand Down
34 changes: 25 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ CROSS_PREFIX :=
CC=$(CROSS_PREFIX)gcc
STRIP=$(CROSS_PREFIX)strip

override CFLAGS+=-O3 -std=c99 -pedantic -Wall -Wextra
PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
SRCDIR=src
INCLUDEDIR=include
BUILDDIR=build
SRCS := $(wildcard $(SRCDIR)/*.c)
OBJS := $(patsubst $(SRCDIR)/%.c,$(BUILDDIR)/%.o,$(SRCS))

override CFLAGS+=-O3 -std=c99 -I$(INCLUDEDIR) -pedantic -Wall -Wextra
override LDFLAGS+=-lnetfilter_queue -lnfnetlink -lmnl

ifdef VERSION
override CFLAGS += -DVERSION=\"$(VERSION)\"
override CFLAGS += -DVERSION=\"$(VERSION)\"
endif

PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
BUILDDIR=build

FAKEHTTP=$(BUILDDIR)/fakehttp

ifeq ($(STATIC), 1)
Expand All @@ -24,16 +28,28 @@ all: $(FAKEHTTP)
clean:
$(RM) -r $(BUILDDIR)

$(FAKEHTTP): src/fakehttp.c
$(BUILDDIR):
mkdir -p $(BUILDDIR)
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)

$(BUILDDIR)/%.d: $(SRCDIR)/%.c | $(BUILDDIR)
$(CC) $(CFLAGS) -MM -MT $(@:.d=.o) $< -MF $@

$(BUILDDIR)/%.o: $(SRCDIR)/%.c | $(BUILDDIR)
$(CC) $(CFLAGS) -c $< -o $@

$(FAKEHTTP): $(OBJS) $(MKS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)
$(STRIP) $@

install: all
mkdir -p $(DESTDIR)$(BINDIR)
install -m 755 fakehttp $(DESTDIR)$(BINDIR)/fakehttp
install -m 755 $(FAKEHTTP) $(DESTDIR)$(BINDIR)/fakehttp

uninstall:
$(RM) $(DESTDIR)$(BINDIR)/fakehttp

.PHONY: all clean install uninstall

ifneq ($(MAKECMDGOALS),clean)
-include $(OBJS:.o=.d)
endif
47 changes: 47 additions & 0 deletions include/globvar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* globvar.h - FakeHTTP: https://github.com/MikeWang000000/FakeHTTP
*
* Copyright (C) 2025 MikeWang000000
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FH_GLOBVAR_H
#define FH_GLOBVAR_H

#include <stdint.h>
#include <stdio.h>

struct fh_context {
int exit;
int sockfd;
FILE *logfp;

/* -d */ int daemon;
/* -h */ const char *hostname;
/* -i */ const char *iface;
/* -k */ int killproc;
/* -m */ uint32_t fwmark;
/* -n */ uint32_t nfqnum;
/* -r */ int repeat;
/* -s */ int silent;
/* -t */ uint8_t ttl;
/* -w */ const char *logpath;
/* -x */ uint32_t fwmask;
/* -z */ int use_iptables;
};

extern struct fh_context g_ctx;

#endif /* FH_GLOBVAR_H */
27 changes: 27 additions & 0 deletions include/ipv4ipt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* ipv4ipt.h - FakeHTTP: https://github.com/MikeWang000000/FakeHTTP
*
* Copyright (C) 2025 MikeWang000000
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FH_IPV4IPT_H
#define FH_IPV4IPT_H

int fh_ipt4_flush(int auto_create);

int fh_ipt4_add(void);

#endif /* FH_IPV4IPT_H */
27 changes: 27 additions & 0 deletions include/ipv4nft.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* ipv4nft.h - FakeHTTP: https://github.com/MikeWang000000/FakeHTTP
*
* Copyright (C) 2025 MikeWang000000
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FH_IPV4NFT_H
#define FH_IPV4NFT_H

int fh_nft4_flush(int auto_create);

int fh_nft4_add(void);

#endif /* FH_IPV4NFT_H */
31 changes: 31 additions & 0 deletions include/ipv4pkt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* ipv4pkt.h - FakeHTTP: https://github.com/MikeWang000000/FakeHTTP
*
* Copyright (C) 2025 MikeWang000000
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FH_IPV4PKT_H
#define FH_IPV4PKT_H

#include <stdint.h>
#include <stdlib.h>

int fh_pkt4_make(char *buffer, size_t buffer_size, uint32_t saddr_be,
uint32_t daddr_be, uint16_t sport_be, uint16_t dport_be,
uint32_t seq_be, uint32_t ackseq_be, int psh,
char *tcp_payload, size_t tcp_payload_size);

#endif /* FH_IPV4PKT_H */
29 changes: 29 additions & 0 deletions include/ipv6ipt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* ipv6ipt.h - FakeHTTP: https://github.com/MikeWang000000/FakeHTTP
*
* Copyright (C) 2025 MikeWang000000
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FH_IPV6IPT_H
#define FH_IPV6IPT_H

/* TODO: NOT IMPLEMENTED */
int fh_ipt6_flush(int auto_create);

/* TODO: NOT IMPLEMENTED */
int fh_ipt6_add(void);

#endif /* FH_IPV6IPT_H */
29 changes: 29 additions & 0 deletions include/ipv6nft.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* ipv6nft.h - FakeHTTP: https://github.com/MikeWang000000/FakeHTTP
*
* Copyright (C) 2025 MikeWang000000
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FH_IPV6NFT_H
#define FH_IPV6NFT_H

/* TODO: NOT IMPLEMENTED */
int fh_nft6_flush(int auto_create);

/* TODO: NOT IMPLEMENTED */
int fh_nft6_add(void);

#endif /* FH_IPV6NFT_H */
32 changes: 32 additions & 0 deletions include/ipv6pkt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* ipv6pkt.h - FakeHTTP: https://github.com/MikeWang000000/FakeHTTP
*
* Copyright (C) 2025 MikeWang000000
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FH_IPV6PKT_H
#define FH_IPV6PKT_H

#include <stdint.h>
#include <stdlib.h>

/* TODO: NOT IMPLEMENTED */
int fh_pkt6_make(char *buffer, size_t buffer_size, uint8_t *saddr_be,
uint8_t *daddr_be, uint16_t sport_be, uint16_t dport_be,
uint32_t seq_be, uint32_t ackseq_be, int psh,
char *tcp_payload, size_t tcp_payload_size);

#endif /* FH_IPV6PKT_H */
39 changes: 39 additions & 0 deletions include/logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* logging.h - FakeHTTP: https://github.com/MikeWang000000/FakeHTTP
*
* Copyright (C) 2025 MikeWang000000
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FH_LOGGING_H
#define FH_LOGGING_H

#define E(...) fh_logger(__func__, __FILE__, __LINE__, __VA_ARGS__)
#define E_RAW(...) fh_logger_raw(__VA_ARGS__)
#define E_INFO(...) \
if (!g_ctx.silent) { \
E(__VA_ARGS__); \
}

int fh_logger_setup(void);

void fh_logger_cleanup(void);

void fh_logger(const char *funcname, const char *filename, unsigned long line,
const char *fmt, ...);

void fh_logger_raw(const char *fmt, ...);

#endif /* FH_LOGGING_H */
25 changes: 25 additions & 0 deletions include/mainfun.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* mainfun.h - FakeHTTP: https://github.com/MikeWang000000/FakeHTTP
*
* Copyright (C) 2025 MikeWang000000
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FH_MAINFUN_H
#define FH_MAINFUN_H

int main(int argc, char *argv[]);

#endif /* FH_MAINFUN_H */
Loading