Skip to content

Commit b9cf1f5

Browse files
authored
Add a --not-preferred flag to set preferred_lft to 0 (#38)
* Resolve RTNL_API.addr() takes 2 positional arguments but 3 were given with pyroute2 0.9.1 and above * Add --not-preferred flag to set the random address as not preferred * Update README with --not-preferred
1 parent fdf8451 commit b9cf1f5

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ smart-ipv6-rotator.py run [-h] [--services {google}] [--external-ipv6-ranges EXT
7575
- `--no-services`: Completely disable the --services flag.
7676
- `--ipv6range IPV6RANGE`: Your IPV6 range (e.g., 2407:7000:9827:4100::/64).
7777
- `--cron`: Do not check if the IPv6 address configured will work properly. Useful for CRON and when you know that the IPv6 range is correct.
78-
- `--log-level {CRITICAL,FATAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}`: Sets log level
78+
- `--log-level {CRITICAL,FATAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}`: Sets log level.
79+
- `--not-preferred`: Set the preferred_lft of the IPv6 address to 0
7980

8081
---
8182

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "1.0.0"
44
requires-python = ">=3.9"
55
dependencies = [
66
"requests>=2.31.0",
7-
"pyroute2==0.8.1",
7+
"pyroute2>=0.9.1",
88
]
99
authors = [
1010
{name = "unixfox"},

smart_ipv6_rotator/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def run(
101101
cron: bool = False,
102102
interface: str | None = None,
103103
gateway: str | None = None,
104+
not_preferred: bool = False,
104105
) -> None:
105106
"""Run the IPv6 rotator process."""
106107

@@ -115,6 +116,12 @@ def run(
115116
"Running without checking if the IPv6 address configured will work properly."
116117
)
117118

119+
if not_preferred is True:
120+
preferred_value = 0
121+
else:
122+
# A value of None defaults to a preferred_lft of forever
123+
preferred_value = None
124+
118125
root_check(skip_root)
119126
check_ipv6_connectivity()
120127

@@ -170,9 +177,10 @@ def run(
170177
try:
171178
IPROUTE.addr(
172179
"add",
173-
default_interface_index,
180+
index=default_interface_index,
174181
address=random_ipv6_address,
175182
mask=ipv6_network.prefixlen,
183+
preferred=preferred_value,
176184
)
177185
except Exception as error:
178186
clean_ranges(service_ranges, skip_root)
@@ -325,6 +333,12 @@ def main() -> None:
325333
help="Specify the IPv6 gateway to use.",
326334
required=False,
327335
)
336+
run_parser.add_argument(
337+
"--not-preferred",
338+
action="store_true",
339+
help="Set the preferred_lft of the IPv6 address to 0.",
340+
required=False,
341+
)
328342
run_parser.set_defaults(func=run)
329343

330344
clean_one_parser = subparsers.add_parser(

smart_ipv6_rotator/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def clean_ranges(ranges_: list[str], skip_root: bool) -> None:
124124
try:
125125
IPROUTE.addr(
126126
"del",
127-
previous.interface_index,
127+
index=previous.interface_index,
128128
address=previous.random_ipv6_address,
129129
mask=previous.random_ipv6_address_mask,
130130
)

0 commit comments

Comments
 (0)