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

Pi-hole FTL v5.24 #1822

Merged
merged 20 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bea02c2
Merge pull request #1568 from pi-hole/master
PromoFaux May 28, 2023
aa55889
Bump actions/checkout from 3.4.0 to 3.5.3
dependabot[bot] Jun 10, 2023
c2e0ed6
Merge pull request #1572 from pi-hole/dependabot-github_actions-devel…
DL6ER Jun 10, 2023
40bf4ff
Merge pull request #1584 from pi-hole/master
DL6ER Jul 9, 2023
305e55f
Bump actions/upload-artifact from 3.1.2 to 3.1.3
dependabot[bot] Sep 9, 2023
b7c988c
Merge pull request #1589 from pi-hole/master
PromoFaux Sep 10, 2023
7e83fdb
Group dependabot PRs
yubiuser Jul 1, 2023
61a3658
Merge pull request #1632 from pi-hole/dependabot-github_actions-devel…
PromoFaux Sep 10, 2023
f980bdc
Bump actions/checkout from 3.5.3 to 3.6.0
dependabot[bot] Sep 11, 2023
ade6e67
Merge pull request #1624 from pi-hole/dependabot-github_actions-devel…
DL6ER Sep 17, 2023
d992e92
Fix possible race-collision leading to a theoretical out-of-bounds read
DL6ER Nov 22, 2023
05b6894
Change priorities such that special domains (Firefox and Apple at thi…
DL6ER Dec 6, 2023
caa728a
Bump actions/stale from 8.0.0 to 9.0.0
dependabot[bot] Dec 9, 2023
9b19917
Add special non-interactive mode for the embedded sqlite3 engine acce…
DL6ER Dec 9, 2023
7e4f108
Apply suggestions from code review
DL6ER Dec 9, 2023
a86ea8f
Merge pull request #1820 from pi-hole/new/sql_ni_v5
DL6ER Dec 9, 2023
fd114e0
Merge pull request #1777 from pi-hole/fix/many_clients
DL6ER Dec 10, 2023
fd51d0c
Merge pull request #1814 from pi-hole/dependabot-github_actions-devel…
DL6ER Dec 10, 2023
dfbdaaa
Merge pull request #1808 from pi-hole/tweak/special_domains_prio_v5
DL6ER Dec 13, 2023
42be80e
Merge pull request #1576 from pi-hole/group_dependabot
PromoFaux Jan 6, 2024
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
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ updates:
pull-request-branch-name:
# Separate sections of the branch name with a hyphen
separator: "-"
groups:
github_action-dependencies:
patterns:
- "*"

# As above, but for development-v6
- package-ecosystem: github-actions
directory: "/"
Expand All @@ -27,3 +32,8 @@ updates:
pull-request-branch-name:
# Separate sections of the branch name with a hyphen
separator: "-"
groups:
github_action-dependencies:
patterns:
- "*"

8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
steps:
-
name: Checkout code
uses: actions/checkout@v3.5.2
uses: actions/checkout@v3.6.0
-
name: "Calculate required variables"
id: variables
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
steps:
-
name: Checkout code
uses: actions/checkout@v3.5.2
uses: actions/checkout@v3.6.0
-
name: "Fix ownership of repository"
run: chown -R root .
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
-
name: Upload artifacts to job for later processing
if: github.event_name != 'pull_request'
uses: actions/[email protected].2
uses: actions/[email protected].3
with:
name: tmp-binary-storage
path: '${{ matrix.bin_name }}*'
Expand All @@ -133,7 +133,7 @@ jobs:
steps:
-
name: Checkout code
uses: actions/checkout@v3.5.2
uses: actions/checkout@v3.6.0
-
name: Get Binaries built in previous jobs
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/checkout@v3.5.2
uses: actions/checkout@v3.6.0
-
name: Spell-Checking
uses: codespell-project/actions-codespell@master
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
issues: write

steps:
- uses: actions/stale@v8.0.0
- uses: actions/stale@v9.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 30
Expand All @@ -40,7 +40,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.4.0
uses: actions/checkout@v3.6.0
- name: Remove 'stale' label
run: gh issue edit ${{ github.event.issue.number }} --remove-label ${{ env.stale_label }}
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
pull-requests: write

steps:
- uses: actions/stale@v8.0.0
- uses: actions/stale@v9.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Do not automatically mark PR/issue as stale
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync-back-to-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Syncing branches
steps:
- name: Checkout
uses: actions/checkout@v3.5.2
uses: actions/checkout@v3.6.0
- name: Opening pull request
run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal'
env:
Expand Down
34 changes: 30 additions & 4 deletions src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ void parse_args(int argc, char* argv[])
argv2[5 + j] = argv[i + 2 + j];
exit(sqlite3_shell_main(argc2, argv2));
}
// Special non-interative mode
else if(i+1 < argc && strcmp(argv[i+1], "-ni") == 0)
{
int argc2 = argc - i + 4 - 2;
char **argv2 = calloc(argc2, sizeof(char*));
argv2[0] = argv[0]; // Application name
argv2[1] = (char*)"-batch";
argv2[2] = (char*)"-init";
argv2[3] = (char*)"/dev/null";
// i = "sqlite3"
// i+1 = "-ni"
for(int j = 0; j < argc - i - 2; j++)
argv2[4 + j] = argv[i + 2 + j];
exit(sqlite3_shell_main(argc2, argv2));
}
else
exit(sqlite3_shell_main(argc - i, &argv[i]));
}
Expand Down Expand Up @@ -511,19 +526,30 @@ void parse_args(int argc, char* argv[])
printf(" the script.\n\n");

printf("%sEmbedded SQLite3 shell:%s\n", yellow, normal);
printf("\t%ssql %s[-h]%s, %ssqlite3 %s[-h]%s FTL's SQLite3 shell\n", green, purple, normal, green, purple, normal);
printf("\t%s-h%s starts a special %shuman-readable mode%s\n\n", purple, normal, bold, normal);
printf("\t%ssql%s, %ssqlite3%s FTL's SQLite3 shell\n", green, normal, green, normal);

printf(" Usage: %spihole-FTL sqlite3 %s[-h] %s[OPTIONS] [FILENAME] [SQL]%s\n\n", green, purple, cyan, normal);
printf(" Usage: %spihole-FTL sqlite3 %s[OPTIONS] [FILENAME] [SQL]%s\n\n", green, cyan, normal);
printf(" Options:\n\n");
printf(" - %s[OPTIONS]%s is an optional set of options. All available\n", cyan, normal);
printf(" options can be found in %spihole-FTL sqlite3 --help%s\n", green, normal);
printf(" options can be found in %spihole-FTL sqlite3 --help%s.\n", green, normal);
printf(" The first option can be either %s-h%s or %s-ni%s, see below.\n", purple, normal, purple, normal);
printf(" - %s[FILENAME]%s is the optional name of an SQLite database.\n", cyan, normal);
printf(" A new database is created if the file does not previously\n");
printf(" exist. If this argument is omitted, SQLite3 will use a\n");
printf(" transient in-memory database instead.\n");
printf(" - %s[SQL]%s is an optional SQL statement to be executed. If\n", cyan, normal);
printf(" omitted, an interactive shell is started instead.\n\n");
printf(" There are two special %spihole-FTL sqlite3%s mode switches:\n", green, normal);
printf(" %s-h%s %shuman-readable%s mode:\n", purple, normal, bold, normal);
printf(" In this mode, the output of the shell is formatted in\n");
printf(" a human-readable way. This is especially useful for\n");
printf(" debugging purposes. %s-h%s is a shortcut for\n", purple, normal);
printf(" %spihole-FTL sqlite3 %s-column -header -nullvalue '(null)'%s\n\n", green, purple, normal);
printf(" %s-ni%s %snon-interative%s mode\n", purple, normal, bold, normal);
printf(" In this mode, batch mode is enforced and any possibly\n");
printf(" existing .sqliterc file is ignored. %s-ni%s is a shortcut\n", purple, normal);
printf(" for %spihole-FTL sqlite3 %s-batch -init /dev/null%s\n\n", green, purple, normal);
printf(" Usage: %spihole-FTL sqlite3 %s-ni %s[OPTIONS] [FILENAME] [SQL]%s\n\n", green, purple, cyan, normal);

printf("%sEmbedded dnsmasq options:%s\n", yellow, normal);
printf("\t%sdnsmasq-test%s Test syntax of dnsmasq's config\n", green, normal);
Expand Down
6 changes: 3 additions & 3 deletions src/database/network-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,15 +760,15 @@ static int update_netDB_interface(sqlite3 *db, const int network_id, const char

// Loop over all clients known to FTL and ensure we add them all to the database
static bool add_FTL_clients_to_network_table(sqlite3 *db, enum arp_status *client_status, time_t now,
unsigned int *additional_entries)
unsigned int *additional_entries, int num_clients)
{
// Return early if database is known to be broken
if(FTLDBerror())
return false;

int rc = SQLITE_OK;
char hwaddr[128];
for(int clientID = 0; clientID < counters->clients; clientID++)
for(int clientID = 0; clientID < num_clients; clientID++)
{
// Check thread cancellation
if(killed)
Expand Down Expand Up @@ -1536,7 +1536,7 @@ void parse_neighbor_cache(sqlite3* db)

// Loop over all clients known to FTL and ensure we add them all to the
// database
if(!add_FTL_clients_to_network_table(db, client_status, now, &additional_entries))
if(!add_FTL_clients_to_network_table(db, client_status, now, &additional_entries, clients))
return;

// Check thread cancellation
Expand Down
36 changes: 19 additions & 17 deletions src/dnsmasq_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,23 +1392,6 @@ static bool _FTL_check_blocking(int queryID, int domainID, int clientID, const c
break;
}

// Not in FTL's cache. Check if this is a special domain
if(special_domain(query, domainstr))
{
// Set DNS cache properties
dns_cache->blocking_status = SPECIAL_DOMAIN;
dns_cache->force_reply = force_next_DNS_reply;

// Adjust counters
query_blocked(query, domain, client, QUERY_SPECIAL_DOMAIN);

// Debug output
if(config.debug & DEBUG_QUERIES)
logg("Special domain: %s is %s", domainstr, blockingreason);

return true;
}

// Skip all checks and continue if we hit already at least one whitelist in the chain
if(query->flags.whitelisted)
{
Expand All @@ -1419,6 +1402,8 @@ static bool _FTL_check_blocking(int queryID, int domainID, int clientID, const c
return false;
}

// when we reach this point: the query is not in FTL's cache (for this client)

// Make a local copy of the domain string. The string memory may get
// reorganized in the following. We cannot expect domainstr to remain
// valid for all time.
Expand All @@ -1432,6 +1417,23 @@ static bool _FTL_check_blocking(int queryID, int domainID, int clientID, const c
if(!query->flags.whitelisted)
query->flags.whitelisted = in_regex(domainstr, dns_cache, client->id, REGEX_WHITELIST);

// Check if this is a special domain
if(!query->flags.whitelisted && special_domain(query, domainstr))
{
// Set DNS cache properties
dns_cache->blocking_status = SPECIAL_DOMAIN;
dns_cache->force_reply = force_next_DNS_reply;

// Adjust counters
query_blocked(query, domain, client, QUERY_SPECIAL_DOMAIN);

// Debug output
if(config.debug & DEBUG_QUERIES)
logg("Special domain: %s is %s", domainstr, blockingreason);

return true;
}

// Check blacklist (exact + regex) and gravity for queried domain
unsigned char new_status = QUERY_UNKNOWN;
bool db_okay = true;
Expand Down