aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet/libalias
Commit message (Collapse)AuthorAgeFilesLines
* machine/stdarg.h -> sys/stdarg.hBrooks Davis2025-06-112-2/+2
| | | | | | | | | | | | | Switch to using sys/stdarg.h for va_list type and va_* builtins. Make an attempt to insert the include in a sensible place. Where style(9) was followed this is easy, where it was ignored, aim for the first block of sys/*.h headers and don't get too fussy or try to fix other style bugs. Reviewed by: imp Exp-run by: antoine (PR 286274) Pull Request: https://github.com/freebsd/freebsd-src/pull/1595
* libalias: Handle GetNewPort() errors properlyMark Johnston2025-04-186-112/+178
| | | | | | | | | | | | | | | | | | | AddLink() fails when memory allocation fails or no free port is available; both are error conditions. However, functions such as FindUdpTcpIn() were converting such failures to PKT_ALIAS_IGNORED, which effectively means, "pass the packet without translation," which isn't what we want. Fix the problem by making sure that AddLink() errors are converted to PKT_ALIAS_ERROR where appropriate. The diff is a bit large but is mostly mechanical: functions like TcpAliasOut() are converted to return a result code, and an additional out-parameter is added to return the alias_link pointer. Reported by: Yuxiang Yang <yangyx22@mails.tsinghua.edu.cn> Tested by: Yuxiang Yang <yangyx22@mails.tsinghua.edu.cn> MFC after: 2 months Differential Revision: https://reviews.freebsd.org/D47778
* man: Remove references to classful networksOlivier Cochard2025-02-041-4/+4
| | | | | | | | | Update wording in manual pages to replace references to classful networks with CIDR notation. Approved by: glebius, dhw Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D48853
* libalias: Add support for EIM NATDamjan Jovanovic2024-12-055-17/+132
| | | | | | | | | | | | | | Add support for endpoint-independent mapping ("full cone NAT") in Libalias's UDP NAT. This conforms to RFC 4787 requirements 1 and 3. All UDP packets sent out from a particular internal address:port leave via the same NAT address:port, regardless of their destination. Add some libalias tests and supporting defines. Reviewed by: igoro, thj Differential Revision: https://reviews.freebsd.org/D46689D
* tcp: extend the use of the th_flags accessor functionRichard Scheffenegger2024-11-296-14/+14
| | | | | | | | | | | Formally, there are 12 bits for TCP header flags. Use the accessor functions in more (kernel) places. No functional change. Reviewed By: cc, #transport, cy, glebius, #iflib, kbowling Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D47063
* libalias: add another check to previous changeEugene Grosbein2024-08-201-0/+3
| | | | | | | | | If UseLink() returns NULL, it is possible that Deletelink() has already freed "grp", so check it out carefully. PR: 269770 Reported by: Peter Much X-MFC-With: 8132e959099f0c533f698d8fbc17386f9144432f
* libalias: fix subtle racy problem in outside-inside forwardingEugene Grosbein2024-08-191-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | sys/netinet/libalias/alias_db.c has internal static function UseLink() that passes a link to CleanupLink() to verify if the link has expired. If so, UseLink() may return NULL. _FindLinkIn()'s usage of UseLink() is not quite correct. Assume there is "redirect_port udp" configured to forward incoming traffic for specific port to some internal address. Such a rule creates partially specified permanent link. After first such packet libalias creates new fully specifiled temporary LINK_UDP with default timeout 60 seconds. Also, in case of low traffic libalias may assign "timestamp" for this new temporary link way in the past because LibAliasTime is updated seldom and can keep old value for tens of seconds, and it will be used for the temporary link. It may happen that next incoming packet for redirected port passed to _FindLinkIn() results in a call to UseLink() that returns NULL due to detected expiration. Immediate return of NULL results in broken translation: either a packet is dropped (deny_incoming mode) or delivered to original destination address instead of internal one. Fix it with additional check for NULL to proceed with a search for original partially specified link. In case of UDP, it also recreates temporary fully specified link with a call to ReLink(). Practical examples are "redirect_port udp" rules for unidirectional SYSLOG protocol (port 514) or some low volume VPN encapsulated in UDP. Thanks to Peter Much for initial analysis and first version of a patch. Reported by: Peter Much <pmc@citylink.dinoex.sub.org> PR: 269770 MFC after: 1 week
* sys: Remove $FreeBSD$: one-line bare tagWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*\$FreeBSD\$$\n/
* sys: Remove $FreeBSD$: two-line nroff patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-1611-22/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: one-line .c comment patternWarner Losh2023-08-162-2/+0
| | | | Remove /^/[*/]\s*\$FreeBSD\$.*\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-164-8/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* Update various sys/netinet source files to conform with the style(9)Richard Scheffenegger2023-06-201-1/+1
| | | | | | | | | | guide on how to label FALLTHOUGH in switch statements. No functional chance. Reviewed By: tuexen, cc, #transport Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D40622
* spdx: Simplify BSD-2-Clause AND BSD-2-ClauseWarner Losh2023-05-121-1/+1
| | | | | | | | | After removing the -FreeBSD and -NetBSD, we're left with a nuber of BSD-2-Clause AND BSD-2-Clause, so tidy that up. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1217-17/+17
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* libalias: Mark set but unused variables as unused.John Baldwin2023-04-101-1/+1
| | | | | | | This function is clearly a stub, but it seems better to leave the stub bits in place than to remove the function entirely. Differential Revision: https://reviews.freebsd.org/D39355
* libalias: improve handling of invalid SCTP packetsMichael Tuexen2022-11-151-4/+7
| | | | | | | | In case of a paritial chunk only pretend the result is OK if the packet is not the last fragment and there is a valid association. PR: 267476 MFC after: 3 days
* ipfw: Have NAT steal the TH_RES1 bit, instead of the TH_AE bitRichard Scheffenegger2022-11-095-8/+8
| | | | | | | | | | | | The NAT module use of the tcphdr.th_x2 field now collides with the use of this TCP header flag as AccECN (AE) bit. Use the topmost bit instead to allow negotiation of AccECN across a NAT device. Event: IETF 115 Hackathon Reviewed By: #transport, tuexen MFC after: 3 days Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D37300
* libalias(3): Fix two typos in source code commentsGordon Bergling2022-04-091-1/+1
| | | | | | - s/modfied/modified/ MFC after: 3 days
* libalias: Remove unused variables.John Baldwin2022-04-063-14/+5
|
* alias_nbt: Move debug-only variable under #ifdef LIBALIAS_DEBUG.John Baldwin2022-04-061-1/+3
|
* Fix fragmented UDP packets handling since rev.360967.Maxim Sobolev2021-10-151-105/+120
| | | | | | | | | Consider IP_MF flag when checking length of the UDP packet to match the declared value. Sponsored by: Sippy Software, Inc. Differential Revision: https://reviews.freebsd.org/D32363 MFC after: 2 weeks
* libalias: fix divide by zero causing panicStefan Eßer2021-07-101-1/+1
| | | | | | | | | | | | | | | | | The packet_limit can fall to 0, leading to a divide by zero abort in the "packets % packet_limit". An possible solution would be to apply a lower limit of 1 after the calculation of packet_limit, but since any number modulo 1 gives 0, the more efficient solution is to skip the modulo operation for packet_limit <= 1. Since this is a fix for a panic observed in stable/12, merging this fix to stable/12 and stable/13 before expiry of the 3 day waiting period might be justified, if it works for the reporter of the issue. Reported by: Karl Denninger <karl@denninger.net> MFC after: 3 days
* libalias: Remove a stray directiveLutz Donnerhacke2021-07-041-1/+0
| | | | | | | Removal of a preprocessor line was missed during development. Do it now and MFC it together with the other patches. MFC after: 2 days
* libalias: Rewrite HISTORYLutz Donnerhacke2021-07-041-2/+3
| | | | | | | Fix the history entry (wrong year) and add the missing recent work. MFC together with the other patches. MFC after: 2 days
* libalias: Fix API bug on initializationLutz Donnerhacke2021-07-031-3/+9
| | | | | | | | | | | | | The kernel part of ipfw(8) does initialize LibAlias uncondistionally with an zeroized port range (allowed ports from 0 to 0). During restucturing of libalias, port ranges are used everytime and are therefor initialized with different values than zero. The secondary initialization from ipfw (and probably others) overrides the new default values and leave the instance in an unfunctional state. The obvious solution is to detect such reinitializations and use the new default value instead. MFC after: 3 days
* libalias: Avoid uninitialized expirationLutz Donnerhacke2021-07-021-2/+0
| | | | | | | | | | The expiration time of direct address mappings is explicitly uninitialized. Expire times are always compared during housekeeping. Despite the uninitialized value does not harm, it's simpler to just set it to a reasonable default. This was detected during valgrinding the test suite. MFC after: 3 days
* libalias: Fix splay comparsion bugLutz Donnerhacke2021-07-021-6/+7
| | | | | | | | | | | | | | | | | | | | Comparing elements in a tree requires transitiviy. If a < b and b < c then a must be smaller than c. This way the tree elements are always pairwise comparable. Tristate comparsion functions returning values lower, equal, or greater than zero, are usually implemented by a simple subtraction of the operands. If the size of the operands are equal to the size of the result, integer modular arithmetics kick in and violates the transitivity. Example: Working on byte with 0, 120, and 240. Now computing the differences: 120 - 0 = 120 240 - 120 = 120 240 - 0 = -16 MFC after: 3 days
* libalias: Fix compile time warning about unused functionsLutz Donnerhacke2021-06-232-403/+444
| | | | | | | | | | | | Compiling libalias results in warnings about unused functions. Those warnings are caused by clang's heuristic to consider an inline function as in use, iff the declaration is in a *.c file. Declarations in *.h files do not emit those warnings. Hence the declarations must be moved to an extra *.h file. MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D30844
* libalias: Switch to efficient data structure for incoming trafficLutz Donnerhacke2021-06-192-45/+36
| | | | | | | | | | | | | | | | | | | | | Current data structure is using a hash of unordered lists. Those unordered lists are quite efficient, because the least recently inserted entries are most likely to be used again. In order to avoid long search times in other cases, the lists are hashed into many buckets. Unfortunatly a search for a miss needs an exhaustive inspection and a careful definition of the hash. Splay trees offer a similar feature: Almost O(1) for access of the least recently used entries, and amortized O(ln(n)) for almost all other cases. Get rid of the hash. Now the data structure should able to quickly react to external packets without eating CPU cycles for breakfast, preventing a DoS. PR: 192888 Discussed with: Dimitry Luhtionov MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30536
* libalias: Switch to efficient data structure for outgoing trafficLutz Donnerhacke2021-06-192-49/+36
| | | | | | | | | | | | | | | | | Current data structure is using a hash of unordered lists. Those unordered lists are quite efficient, because the least recently inserted entries are most likely to be used again. In order to avoid long search times in other cases, the lists are hashed into many buckets. Unfortunatly a search for a miss needs an exhaustive inspection and a careful definition of the hash. Splay trees offer a similar feature - almost O(1) for access of the least recently used entries), and amortized O(ln(n) - for almost all other cases. Get rid of the hash. Discussed with: Dimitry Luhtionov MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30516
* libalias: Restructure - FinalizeLutz Donnerhacke2021-06-191-0/+1
| | | | | | | Note, that the restructuring is done. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30582
* libalias: Restructure - Remove temporary state deleteAllLinks from global structLutz Donnerhacke2021-06-192-36/+25
| | | | | | | | The entry deleteAllLinks in the struct libalias is only used to signal a state between internal calls. It's not used between API calls. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30604
* libalias: Restructure - Use AliasRange instead of PORT_BASELutz Donnerhacke2021-06-191-97/+74
| | | | | | | | | Get rid of PORT_BASE, replace by AliasRange. Simplify code. Factor out the search for a new port. Improves the perfomance a bit. Discussed with: Dimitry Luhtionov MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30581
* libalias: Restructure - Table for PPTPLutz Donnerhacke2021-06-192-167/+187
| | | | | | | | Let PPTP use its own data structure. Regroup and rename other lists, which are not PPTP. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30580
* libalias: Restructure - Group expire handling entriesLutz Donnerhacke2021-06-191-21/+23
| | | | | | | Reorder the internal structure semantically. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30575
* libalias: Restructure - Group incoming linksLutz Donnerhacke2021-06-192-96/+136
| | | | | | | | | | | Reorder incoming links by grouping of common search terms. Significant performance improvement for incoming (missing) flows. Remove LSNAT from outgoing search. Slight speedup due to less comparsions in the loop. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30574
* libalias: Restructure - Cleanup and Use for linksLutz Donnerhacke2021-06-191-16/+17
| | | | | | | Factor out a common idiom to return found links. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30573
* libalias: Restructure - Outgoing searchLutz Donnerhacke2021-06-191-27/+40
| | | | | | | | Factor out the outgoing search function. Preparation for a new data structure. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30572
* libalias: Restructure - Cleanup _FindLinkInLutz Donnerhacke2021-06-191-25/+19
| | | | | | | Simplify program flow in function _FindLinkIn. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30571
* libalias: Restructure - Table for partially linksLutz Donnerhacke2021-06-192-24/+52
| | | | | | | | | | | Separate the partially specified links into a separate data structure. This would causes a major parformance impact, if there are many of them. Use a (smaller) hash table to speed up the partially link access. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30570
* libalias: Restructure - Separate fully qualified searchLutz Donnerhacke2021-06-191-12/+17
| | | | | | | | Search fully specified links first. Some performance loss due to need to revisit the db twice, if not found. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30569
* libalias: Restructure - Common search termsLutz Donnerhacke2021-06-191-24/+24
| | | | | | | | Factor out the common Out and In filter Slightly better performance due to eager skip of search loop MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30568
* libalias: Promote per instance global variable timeStampLutz Donnerhacke2021-06-193-31/+50
| | | | | | | | | | | | Summary: - Use LibAliasTime as a real global variable for central timekeeping. - Reduce number of syscalls in user space considerably. - Dynamically adjust the packet counters to match the second resolution. - Only check the first few packets after a time increase for expiry. Discussed with: hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30566
* libalias: Stats are unsignedLutz Donnerhacke2021-06-191-8/+8
| | | | | | | | Stats counters are used as unsigned valued (i.e. printf("%u")) but are defined as signed int. This causes trouble later, so fix it early. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30587
* libalias: tidy up housekeepingLutz Donnerhacke2021-06-102-63/+47
| | | | | | | | | | | | | | | Replace current expensive, but sparsly called housekeeping by a single, repetive action. This is part of a larger restructure of libalias in order to switch to more efficient data structures. The whole restructure process is split into 15 reviews to ease reviewing. All those steps will be squashed into a single commit for MFC in order to hide the intermediate states from production systems. Reviewed by: hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30277
* libalias: Remove LibAliasCheckNewLinkLutz Donnerhacke2021-05-313-11/+3
| | | | | | | Finally drop the function in 14-CURRENT. Discussed with: kp Differential Revision: https://reviews.freebsd.org/D30275
* libalias: Remove unused function LibAliasCheckNewLinkLutz Donnerhacke2021-05-315-32/+7
| | | | | | | | | | | | | | | | The functionality to detect a newly created link after processing a single packet is decoupled from the packet processing. Every new packet is processed asynchronously and will reset the indicator, hence the function is unusable. I made a Google search for third party code, which uses the function, and failed to find one. That's why the function should be removed: It unusable and unused. A much simplified API/ABI will remain in anything below 14. Discussed with: kp Reviewed by: manpages (bcr) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30275
* libalias: Fix nameing and initialization of a constantLutz Donnerhacke2021-05-301-13/+12
| | | | | | | The commit 189f8eea contains a refactorisation of a constant. During later review D30283 the naming of the constant was improved and the initialization became explicit. Put this into the tree, in order to MFC the correct naming.
* libalias: Ensure ASSERT behind varable declarationsLutz Donnerhacke2021-05-161-2/+2
| | | | | | | | | | At some places the ASSERT was inserted before variable declarations are finished. This is fixed now. Reported by: kib Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30282