Skip to content

Commit

Permalink
Misc formatting fixes (facebook#2)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#2

- drop spurious tabs from the makefiles
- try to make the README mdl compliant

Reviewed By: kernelslacker

Differential Revision: D31490501

fbshipit-source-id: 1874e7f5b2c721c40963caab6f3528c6d7142b14
  • Loading branch information
davide125 authored and facebook-github-bot committed Oct 8, 2021
1 parent cb8df2a commit 30fa51a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 51 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ jobs:
uses: actions/checkout@v2
- name: Build netconsd
run: make
# FIXME disable for now, the markdown docs here need lots of work
# markdown:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout repository
# uses: actions/checkout@v2
# - name: Lint Markdown
# uses: actionshub/[email protected]
# - name: Check links
# uses: gaurav-nelson/[email protected]
- name: Build netconsblaster
run: make -C util
markdown:
name: Markdown
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Lint Markdown
uses: actionshub/[email protected]
- name: Check links
uses: gaurav-nelson/[email protected]
1 change: 1 addition & 0 deletions .mdlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rules '~MD013', '~MD014', '~MD029', '~MD034'
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# Contributing to netconsd

We want to make contributing to this project as easy and transparent as
possible.

## Our Development Process

This repository is synced from an internal repository. We gladly accept
pull requests and will deal with the merging appropriately.

## Contributor License Agreement ("CLA")

In order to accept your pull request, we need you to submit a CLA. You only
need to do this once to work on any of Facebook's open source projects.

Complete your CLA here: <https://code.facebook.com/cla>

## Issues

We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.

Expand All @@ -21,12 +25,14 @@ safe disclosure of security bugs. In those cases, please go through the
process outlined on that page and do not file a public issue.

## Sending a pull request

Have a fix or feature? Awesome! When you send the pull request we suggest you
include a build output.

We will hold all contributions to the same quality and style standards as the
existing code.

## License

By contributing to this repository, you agree that your contributions will be
licensed in accordance to the LICENSE document in the root of this repository.
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ LDFLAGS ?= -shared
LIBS = -lpthread -lrt -ldl
CFLAGS ?= -O2 -fPIC
CFLAGS += -D_GNU_SOURCE -fno-strict-aliasing -Wall -Wextra \
-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
-Wdeclaration-after-statement -Wno-missing-field-initializers \
-Wno-unused-parameter
-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
-Wdeclaration-after-statement -Wno-missing-field-initializers \
-Wno-unused-parameter
INCLUDES = -Incrx

debug debug32: CFLAGS += -O0 -gdwarf-4 -fno-omit-frame-pointer \
-fstack-protector-all -fsanitize=address -fsanitize=undefined
debug debug32: LDFLAGS := -lasan -lubsan $(LDFLAGS)
-fstack-protector-all -fsanitize=address \
-fsanitize=undefined
debug debug32: LDFLAGS += -lasan -lubsan $(LDFLAGS)

32bit: CFLAGS += -m32
32bit: LDFLAGS += -m32
Expand Down
67 changes: 37 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ The Makefile includes a few other handy targets:
* `32bit`: Forces 32-bit compilation on x86_64 systems, for easily
testing portability to 32-bit CPU architectures. You'll need
to install 32-bit libraries if your distro doesn't have them.
* `debug32`: Union of the "32bit" and "debug" targets.
* `disasm`: Emits verbose annotated disassembly in *.s files.
* `debug32`: Union of the `32bit` and `debug` targets.
* `disasm`: Emits verbose annotated disassembly in `*.s` files.

If you want to build the daemon with clang, just append `CC="clang"` to your
make invocation. All the above targets should build with both clang and gcc.
Expand All @@ -41,7 +41,7 @@ make invocation. All the above targets should build with both clang and gcc.
### Setting up the server

By default, netconsd will use 1 listener and 2 worker threads, and listen on
port 1514 for messages. You can use "-l", "-w", and "-u" respectively to change
port 1514 for messages. You can use `-l`, `-w`, and `-u` respectively to change
the defaults.

There's no universal wisdom about how many threads to use: just experiment with
Expand All @@ -66,15 +66,18 @@ no reason to make that configurable: if you care, open an issue and we will.

The netconsole module takes a parameter like this:

netconsole=${sport}@${saddr}/${intf},${dport}@${daddr}/${dmac}
```
netconsole=${sport}@${saddr}/${intf},${dport}@${daddr}/${dmac}
```

The fields are as follows:
1) sport: Source port for the netconsole UDP packets
2) saddr: Source address for the netconsole UDP packets
3) intf: The name of the interface to send the UDP packets from
4) dport: Destination port for the netconsole UDP packets
5) daddr: Destination address for the netconsole UDP packets
6) dmac: Destination L2 MAC address for the netconsole UDP packets

1. `sport`: Source port for the netconsole UDP packets
2. `saddr`: Source address for the netconsole UDP packets
3. `intf`: The name of the interface to send the UDP packets from
4. `dport`: Destination port for the netconsole UDP packets
5. `daddr`: Destination address for the netconsole UDP packets
6. `dmac`: Destination L2 MAC address for the netconsole UDP packets

We need (6) because of how low-level netconsole is: it can't consult the routing
table to send the packet, so it must know a priori what MAC address to use in
Expand All @@ -84,17 +87,19 @@ If you're talking to a server on the same L2 segment as the client, use the MAC
address of that server. Otherwise, use the MAC address of your router. You can
use the following quick shell one-liners to easily get the MAC of the router:

IPv6: ip -6 neighbor show | grep router
IPv4: sudo arp –a | grep gateway
* IPv6: `ip -6 neighbor show | grep router`
* IPv4: `sudo arp –a | grep gateway`

Here are a couple examples for the parameter above:

IPv6: netconsole=+6666@2401:db00:11:801e:face:0:31:0/eth0,1514@2401:db00:11:d0be:face:0:1b:0/c0:8c:60:3d:0d:bc
IPv4: [email protected]/eth0,[email protected]/00:00:0c:9f:f1:90
```
IPv6: netconsole=+6666@2401:db00:11:801e:face:0:31:0/eth0,1514@2401:db00:11:d0be:face:0:1b:0/c0:8c:60:3d:0d:bc
IPv4: [email protected]/eth0,[email protected]/00:00:0c:9f:f1:90
```

Prepending "+" to the cmdline will cause kernels that support it to use extended
Prepending `+` to the cmdline will cause kernels that support it to use extended
netconsole, which you almost certainly want. Kernels too old to support extcon
will silently ignore the "+".
will silently ignore the `+`.

Once you have your parameter constructed, just insert the module with it:

Expand All @@ -113,7 +118,7 @@ $ sudo bash -c 'echo "Hello world!" > /dev/kmsg'
$ sudo bash -c 'echo "<0>OMG!" > /dev/kmsg'
```

The "<0>" tells the kernel what loglevel to use: 0 is `KERN_EMERG`, which ensures
The `<0>` tells the kernel what loglevel to use: 0 is `KERN_EMERG`, which ensures
your message will actually get transmitted.

## Writing an output module
Expand All @@ -123,48 +128,50 @@ your message will actually get transmitted.
Output modules are shared object files loaded with `dlopen()` at runtime by
netconsd. Netconsd will look for three functions in your module:

1) int netconsd_output_init(int worker_thread_count)
2) void netconsd_output_handler(int thread, struct in6_addr *src, struct msgbuf *buf, struct ncrx_msg *msg)
3) void netconsd_output_exit(void)
1. `int netconsd_output_init(int worker_thread_count)`
2. `void netconsd_output_handler(int thread, struct in6_addr *src, struct msgbuf *buf, struct ncrx_msg *msg)`
3. `void netconsd_output_exit(void)`

If (1) exists, it is called when your module is loaded: the argument tells you
how many worker threads netconsd is going to call your module from. If you
return non-zero from this function, netconsd will abort() and exit.
return non-zero from this function, netconsd will `abort()` and exit.

If (3) exists, it is called when netconsd unloads your module.

For every message it receives, netconsd will call (2) in your module. The code
must be reentrant: `netconsd_output_handler()` will be called concurrently from
all of the worker threads in netconsd. The "thread" argument tells you which
all of the worker threads in netconsd. The `thread` argument tells you which
worker is invoking the function, which makes it easy to have per-thread data.

Netconsd uses a consistent hash to decide which worker to pass messages to, so
messages from same remote address will always be queued to the same thread.

The "src" argument will always point to an `in6_addr` struct containing the source
The `src` argument will always point to an `in6_addr` struct containing the source
address of the netconsole packet. If the source was an IPv4 address, it will be
formatted like "::FFFF:<IPv4 address>" (see "man ipv6" for details).
formatted like `::FFFF:<IPv4 address>` (see `man ipv6` for details).

If the message had extended metadata, "msg" will point to the `ncrx_msg` struct
containing that metadata and "buf" will be NULL. Otherwise, "msg" will be NULL
and "buf" will point to a msgbuf struct with the raw message text.
If the message had extended metadata, `msg` will point to the `ncrx_msg` struct
containing that metadata and `buf` will be `NULL`. Otherwise, `msg` will be `NULL`
and `buf` will point to a `msgbuf` struct with the raw message text.

Output modules must not modify the structures passed in. The memory backing all
the pointers passed in will be freed immediately after the handler returns.

### Building the modules

For modules written in C this is trivial: just compile with "-shared".
For modules written in C this is trivial: just compile with `-shared`.

For modules written in C++ it can be a bit trickier: you will probably need to
build with "-static-libstdc++" and/or "-static-libgcc" to make this work.
build with `-static-libstdc++` and/or `-static-libgcc` to make this work.

See the code and Makefile in modules/ for some examples of the above.
See the code and Makefile in `modules/` for some examples of the above.

## Contributing

See the CONTRIBUTING file for how to help out.

## License

netconsd is BSD licensed, see the LICENSE file for more information.

netconsd was originally written by Calvin Owens as part of
Expand Down
5 changes: 2 additions & 3 deletions modules/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ INCLUDES = -I../ncrx -I../include

# Filter out warnings not cpp-applicable that g++ complains about
CCFLAGS := -std=c++11 $(filter-out -Wstrict-prototypes -Wmissing-prototypes \
-Wdeclaration-after-statement,$(CFLAGS))
-Wdeclaration-after-statement,$(CFLAGS))

mods = printer.so logger.so

Expand All @@ -19,8 +19,7 @@ all: $(mods)

%.so: %.cc
$(CXX) $< $(CCFLAGS) $(INCLUDES) $(LDFLAGS) -c -o $(<:.cc=.o)
$(CXX) $(<:.cc=.o) $(LDFLAGS) \
-o $@
$(CXX) $(<:.cc=.o) $(LDFLAGS) -o $@

clean:
rm -f *.o *.so
6 changes: 3 additions & 3 deletions ncrx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ CC ?= gcc

CFLAGS ?= -O2 -fPIC
CFLAGS += -D_GNU_SOURCE -fno-strict-aliasing -Wall -Wextra \
-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
-Wdeclaration-after-statement -Wno-missing-field-initializers \
-Wno-unused-function -Wno-unused-parameter
-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
-Wdeclaration-after-statement -Wno-missing-field-initializers \
-Wno-unused-function -Wno-unused-parameter

obj = libncrx.o

Expand Down

0 comments on commit 30fa51a

Please sign in to comment.