Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shared memory objects for data #429

Merged
merged 59 commits into from
Dec 12, 2018
Merged

Use shared memory objects for data #429

merged 59 commits into from
Dec 12, 2018

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented Dec 11, 2018

By submitting this pull request, I confirm the following:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

How familiar are you with the codebase?:

10


This PR is a combined effort of @Mcat12 and @DL6ER. It changes the way FTL stores its data internally. Previously, everything was held in private memory. However, after merging this PR, the data will instead be held in POSIX Shared Memory objects, allowing a straightforward sharing with the future API we are currently working on (see here).

Although shared memory objects could be understood as being slightly less secure compared to private memory, however this is not the case. The data is still protected as it is protected with permissions 600, i.e., only the owner (the user pihole) can read and write on the data. This serves the same level of privacy as we do already now.

This template was created based on the work of udemy-dl.

DL6ER and others added 30 commits August 1, 2018 18:04
…ng buffer

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
…tially

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
… assume char* pointer type (use void* and cast at the right places if needed)

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
…ftruncate), and only then mmap() it again

Signed-off-by: DL6ER <dl6er@dl6er.de>
…th "/" for portability

Signed-off-by: DL6ER <dl6er@dl6er.de>
…(). shm_open() automatically sets FD_CLOEXEC which closes the file handler automatically whenever something is calling system() to avoid leaking the file descriptors to random programs. The file descriptor becomes invalid and later mmap operations fail. We always use shm_open() (without the O_CREAT attribute) every time before we run mmap to ensure we always have a valid file descriptor.

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
# Conflicts:
#	api.c
#	dnsmasq_interface.c
The merged in code tried to use normal strings instead of shared memory
strings.

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
unsigned int is smaller than long long, which all of the string position
data was using. This generated a lot of warnings.

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
Previously two NULL bytes were used between strings, which was not
intended.

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
The new size was not remembered after resizing, causing it to never
resize larger than two 4k blocks of items.

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This requires that it be accessed through a pointer, so most of the
changes are just changing `counters.` to `counters->`

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
# Conflicts:
#	dnsmasq_interface.c
#	resolve.c
AzureMarker and others added 13 commits October 11, 2018 15:59
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This is checked by accessors of shared memory to defer to FTL so they do
not starve FTL of access to shared memory (starving DNS resolution).

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
It is no longer needed.

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Store database ID in queries struct
Signed-off-by: DL6ER <dl6er@dl6er.de>
# Conflicts:
#	database.c
#	request.c
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER DL6ER added the API label Dec 11, 2018
@DL6ER DL6ER added this to the v4.2 milestone Dec 11, 2018
@DL6ER
Copy link
Member Author

DL6ER commented Dec 11, 2018

Note that this change does not affect any parts of the API, yet. The goal is to eventually replace FTL's internal telnet API by the future RESTful HTTP API. This will, however, not happen overnight but we plan to keep the existing telnet API for some additional time after releasing the HTTP API. However, no additional features will be added to the telnet API as soon as the HTTP API will be available.

@AzureMarker
Copy link
Contributor

Closing and reopening to try and get Codacy working...

@AzureMarker AzureMarker reopened this Dec 11, 2018
@dschaper
Copy link
Member

Flipping status for CodeFactor check.

@dschaper dschaper closed this Dec 12, 2018
@dschaper dschaper reopened this Dec 12, 2018
@AzureMarker AzureMarker merged commit 88bad8c into development Dec 12, 2018
@AzureMarker AzureMarker deleted the new/shmem branch December 12, 2018 01:11
r00t0vi4 pushed a commit to r00t0vi4/FTL that referenced this pull request Dec 13, 2018
Use shared memory objects for data

Signed-off-by: spb-admin <spb@poligon.ru>
Signed-off-by: r00t0vi4 <r00t0vi4@gmail.com>
r00t0vi4 pushed a commit to r00t0vi4/FTL that referenced this pull request Dec 13, 2018
Use shared memory objects for data

Signed-off-by: r00t0vi4 <r00t0vi4@gmail.com>
@pralor-bot
Copy link

This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/pi-hole-v4-2-available-with-shared-memory-new-blocking-modes-and-more/16763/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants