aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2020-03-25 23:51:53 +0100
committerToni Uhlig <matzeton@googlemail.com>2020-03-25 23:51:53 +0100
commitfe14d74de43e7d900ed1df34933d7d2a131d5e0b (patch)
tree77ac2df9dd6c16ff1fe13dd8a091177aefc29bdf
parentea1e885d303f719c4d9c398771a595d22da41c68 (diff)
initial clang-format file
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--.clang-format77
-rw-r--r--src/pkt.c91
2 files changed, 119 insertions, 49 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..cdf33a6
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,77 @@
+Language: Cpp
+BasedOnStyle : LLVM
+Standard : Cpp03
+# BasedOnStyle: LLVM
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: false
+ AfterNamespace: false
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: true
+ConstructorInitializerIndentWidth: 4
+AlignEscapedNewlinesLeft: false
+AlignTrailingComments: true
+AllowShortBlocksOnASingleLine: true
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: false
+AlwaysBreakTemplateDeclarations: true
+AlwaysBreakBeforeMultilineStrings: true
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+ColumnLimit: 120
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+DerivePointerAlignment: false
+ExperimentalAutoDetectBinPacking: false
+IndentCaseLabels: true
+IndentWrappedFunctionNames: false
+IndentFunctionDeclarationAfterType: false
+MaxEmptyLinesToKeep: 1
+KeepEmptyLinesAtTheStartOfBlocks: true
+NamespaceIndentation: None
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: false
+
+PenaltyExcessCharacter : 500
+PenaltyReturnTypeOnItsOwnLine : 120
+PenaltyBreakBeforeFirstCallParameter : 100
+PenaltyBreakString : 20
+PenaltyBreakComment : 10
+PenaltyBreakFirstLessLess : 0
+
+SpacesBeforeTrailingComments: 1
+Cpp11BracedListStyle: true
+IndentWidth: 4
+TabWidth: 4
+UseTab: Never
+BreakBeforeBraces: Linux
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpacesInAngles : false
+SpaceInEmptyParentheses : false
+SpacesInCStyleCastParentheses : false
+SpaceAfterCStyleCast : false
+SpacesInContainerLiterals : true
+SpaceBeforeAssignmentOperators : true
+ContinuationIndentWidth : 4
+SpaceBeforeParens : ControlStatements
+DisableFormat : false
+AccessModifierOffset : -4
+PointerAlignment : Middle
+AlignAfterOpenBracket : Align
+AllowAllParametersOfDeclarationOnNextLine : true
+BinPackArguments : false
+BinPackParameters : false
+AlignOperands : true
+AlignConsecutiveAssignments : false
+AllowShortFunctionsOnASingleLine : None
+BreakBeforeBinaryOperators : None
+AlwaysBreakAfterReturnType : None
+SortIncludes : false
diff --git a/src/pkt.c b/src/pkt.c
index dc228c1..4274594 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -56,18 +56,18 @@
#include "options.h"
#include "utils.h"
-
-static proxy_desc_t *
-handle_incoming_tunnel_request(unsigned bytes, struct sockaddr_in *addr, int icmp_sock,
- icmp_echo_packet_t * const pkt, ping_tunnel_pkt_t * const pt_pkt)
+static proxy_desc_t * handle_incoming_tunnel_request(unsigned bytes,
+ struct sockaddr_in * addr,
+ int icmp_sock,
+ icmp_echo_packet_t * const pkt,
+ ping_tunnel_pkt_t * const pt_pkt)
{
struct timeval tt;
struct in_addr in_addr;
uint32_t init_state;
- proxy_desc_t *cur;
+ proxy_desc_t * cur;
- pt_log(kLog_info, "Incoming tunnel request from %s.\n",
- inet_ntoa(*(struct in_addr *)&addr->sin_addr));
+ pt_log(kLog_info, "Incoming tunnel request from %s.\n", inet_ntoa(*(struct in_addr *)&addr->sin_addr));
gettimeofday(&tt, 0);
if (tt.tv_sec < seq_expiry_tbl[pt_pkt->id_no]) {
@@ -76,28 +76,27 @@ handle_incoming_tunnel_request(unsigned bytes, struct sockaddr_in *addr, int icm
}
in_addr.s_addr = pt_pkt->dst_ip;
- pt_log(kLog_info, "Starting new session to %s:%d with ID %d\n",
- inet_ntoa(in_addr), ntohl(pt_pkt->dst_port), pt_pkt->id_no);
+ pt_log(kLog_info,
+ "Starting new session to %s:%d with ID %d\n",
+ inet_ntoa(in_addr),
+ ntohl(pt_pkt->dst_port),
+ pt_pkt->id_no);
- if ((opts.restrict_dst_ip && opts.given_dst_ip &&
- opts.given_dst_ip != pt_pkt->dst_ip) ||
+ if ((opts.restrict_dst_ip && opts.given_dst_ip && opts.given_dst_ip != pt_pkt->dst_ip) ||
(opts.restrict_dst_port && (uint32_t)-1 != opts.given_dst_port &&
- opts.given_dst_port != ntohl(pt_pkt->dst_port)))
- {
+ opts.given_dst_port != ntohl(pt_pkt->dst_port))) {
pt_log(kLog_info, "Destination administratively prohibited!\n");
return NULL;
}
if (opts.password) {
- init_state = kProto_authenticate;
+ init_state = kProto_authenticate;
} else {
- init_state = kProto_data;
+ init_state = kProto_data;
}
- cur = (proxy_desc_t *) create_and_insert_proxy_desc(pt_pkt->id_no, pkt->identifier, 0,
- addr, pt_pkt->dst_ip,
- ntohl(pt_pkt->dst_port),
- init_state, kProxy_flag);
+ cur = (proxy_desc_t *)create_and_insert_proxy_desc(
+ pt_pkt->id_no, pkt->identifier, 0, addr, pt_pkt->dst_ip, ntohl(pt_pkt->dst_port), init_state, kProxy_flag);
if (!cur) {
/* if failed, abort. Logging is done in create_insert_proxy_desc */
pt_log(kLog_error, "Failed to create proxy descriptor!\n");
@@ -109,31 +108,31 @@ handle_incoming_tunnel_request(unsigned bytes, struct sockaddr_in *addr, int icm
if (init_state == kProto_authenticate) {
pt_log(kLog_debug, "Sending authentication challenge..\n");
/* Send challenge */
- cur->challenge = generate_challenge();
+ cur->challenge = generate_challenge();
memcpy(cur->buf, cur->challenge, sizeof(challenge_t));
- queue_packet(icmp_sock, cur, cur->buf, sizeof(challenge_t), 0, 0,
- kProto_authenticate | cur->type_flag);
+ queue_packet(icmp_sock, cur, cur->buf, sizeof(challenge_t), 0, 0, kProto_authenticate | cur->type_flag);
}
return cur;
}
-static void handle_auth_request(unsigned bytes, int icmp_sock,
- icmp_echo_packet_t *const pkt,
- proxy_desc_t *const cur,
- challenge_t *const challenge)
+static void handle_auth_request(unsigned bytes,
+ int icmp_sock,
+ icmp_echo_packet_t * const pkt,
+ proxy_desc_t * const cur,
+ challenge_t * const challenge)
{
if (!opts.password) {
- pt_log(kLog_error, "This proxy requires a password! "
- "Please supply one usin g the -x switch.\n");
+ pt_log(kLog_error,
+ "This proxy requires a password! "
+ "Please supply one usin g the -x switch.\n");
send_termination_msg(cur, icmp_sock);
cur->should_remove = 1;
return;
}
#ifdef ENABLE_SHA512
if (opts.force_sha512) {
- pt_log(kLog_debug,
- "Got authentication challenge - sending SHA512 response\n");
+ pt_log(kLog_debug, "Got authentication challenge - sending SHA512 response\n");
generate_response_sha512(&challenge->plain, &challenge->digest);
} else
#endif
@@ -143,8 +142,7 @@ static void handle_auth_request(unsigned bytes, int icmp_sock,
}
memcpy(cur->buf, challenge, sizeof(challenge_t));
- queue_packet(icmp_sock, cur, cur->buf, sizeof(challenge_t), 0, 0,
- kProto_authenticate | cur->type_flag);
+ queue_packet(icmp_sock, cur, cur->buf, sizeof(challenge_t), 0, 0, kProto_authenticate | cur->type_flag);
/* We have authenticated locally.
* It's up to the proxy now if it accepts our response or not..
*/
@@ -152,21 +150,21 @@ static void handle_auth_request(unsigned bytes, int icmp_sock,
handle_data(pkt, bytes, cur);
}
-static void handle_auth_response(unsigned bytes, int icmp_sock,
- icmp_echo_packet_t *const pkt,
- proxy_desc_t *const cur,
- challenge_t *const challenge)
+static void handle_auth_response(unsigned bytes,
+ int icmp_sock,
+ icmp_echo_packet_t * const pkt,
+ proxy_desc_t * const cur,
+ challenge_t * const challenge)
{
- pt_log(kLog_debug, "Received remote %s challenge response.\n",
+ pt_log(kLog_debug,
+ "Received remote %s challenge response.\n",
(challenge->digest.hash_type == HT_SHA512 ? "SHA512" : "MD5"));
if ((!opts.force_sha512 && challenge->digest.hash_type == HT_MD5 &&
validate_challenge_md5(cur->challenge, &challenge->digest)) ||
#ifdef ENABLE_SHA512
- (challenge->digest.hash_type == HT_SHA512 &&
- validate_challenge_sha512(cur->challenge, &challenge->digest)) ||
+ (challenge->digest.hash_type == HT_SHA512 && validate_challenge_sha512(cur->challenge, &challenge->digest)) ||
#endif
- cur->authenticated)
- {
+ cur->authenticated) {
pt_log(kLog_verbose, "Remote end authenticated successfully.\n");
/* Authentication has succeeded, so now we can proceed
* to handle incoming TCP data.
@@ -184,8 +182,7 @@ static void handle_auth_response(unsigned bytes, int icmp_sock,
}
}
-static void header_byteorder_ntoh(icmp_echo_packet_t * const icmp_pkt,
- ping_tunnel_pkt_t * const pt_pkt)
+static void header_byteorder_ntoh(icmp_echo_packet_t * const icmp_pkt, ping_tunnel_pkt_t * const pt_pkt)
{
pt_pkt->state = ntohl(pt_pkt->state);
icmp_pkt->identifier = ntohs(icmp_pkt->identifier);
@@ -299,8 +296,7 @@ void handle_packet(char * buf, unsigned bytes, int is_pcap, struct sockaddr_in *
is_pcap);
/* This test essentially verifies that the packet comes from someone who isn't us. */
- if ((pkt_flag == kUser_flag && type_flag == proxy_flag) ||
- (pkt_flag == proxy_flag && type_flag == kUser_flag)) {
+ if ((pkt_flag == kUser_flag && type_flag == proxy_flag) || (pkt_flag == proxy_flag && type_flag == kUser_flag)) {
pt_pkt->data_len = ntohl(pt_pkt->data_len);
pt_pkt->ack = ntohl(pt_pkt->ack);
if (pt_pkt->state == kProxy_start) {
@@ -471,10 +467,7 @@ void handle_data(icmp_echo_packet_t * pkt, int total_len, proxy_desc_t * cur)
expected_len -= sizeof(ip_packet_t);
}
if (total_len < expected_len) {
- pt_log(kLog_error,
- "Packet not completely received: %d Should be: %d.\n",
- total_len,
- expected_len);
+ pt_log(kLog_error, "Packet not completely received: %d Should be: %d.\n", total_len, expected_len);
pt_log(kLog_debug, "Data length: %d Total length: %d\n", pt_pkt->data_len, total_len);
/* just ignore that packet */
return;