• 2 Posts
  • 81 Comments
Joined 1 year ago
cake
Cake day: July 6th, 2023

help-circle




  • start a process within a specific veth

    That sentence doesn’t make any sense.

    Processes run in network namespaces (netns), and that’s exactly what ip netns exec does.

    A newly created netns via ip netns add has no network connectivity at all. Even (private) localhost is down and you have to run ip link set lo up to bring it up.

    You use veth pairs to connect a virtual device in a network namespace, with a virtual device in the default namespace (or another namespace with internet connectivity).

    You route the VPN server address via the netns veth device and nothing else. Then you run wireguard/OpenVPN inside netns.

    Avoid using systemd since it runs in the default netns by default, even if called from a process running in another netns.

    The way I do it is:

    1. A script for all the network setup:
    ns_con AA
    
    1. A script to run a process in a netns (basically a wrapper around ip netns exec):
    ns_run AA <cmd>
    
    1. Run a termnal app using 2.
    2. Run a tmux session on a separate socket inside terminal app. e.g.
    export DISPLAY=:0 # for X11
    export XDG_RUNTIME_DIR=/run/user/1000 # to connect to already running pipewire...
    # double check this is running in AA ns
    tmux -f -f <alternative_config_file_if_needed> -L NS_AA
    

    I have this in my tmux config:

    set-option -g status-left "[#{b:socket_path}:#I] "
    

    So I always know which socket a tmux session is running on. You can include network info there if you’re still not confident in your setup.

    Now, I can detach that tmux session. Reattaching with tmux -L NS_AA attach from anywhere will give me the session still running in AA.






  • A generic impl is impossible.

    Imagine you want to turn a Into<String> to Some(val.into()) and Option<Into<String>> to val.map(Into::into).

    Now, what if there is a type T where impl From <Option<T>> for String is implemented?
    Then we would have a conflict.

    If you only need this for &str and String, then you can add a wrapper type OptionStringWrapper(Option<String>) and implement From<T> for OptionStringWrapper for all concrete type cases you want to support, and go from there.



  • You could have just mentioned the project in question since its code is public.

    https://git.joinplu.me/plume/plume

    % git grep '#!\[feature'
    plume-common/src/lib.rs:#![feature(associated_type_defaults)]
    plume-front/src/lib.rs:#![feature(decl_macro, proc_macro_hygiene)]
    plume-models/src/lib.rs:#![feature(never_type)]
    plume-models/src/lib.rs:#![feature(proc_macro_hygiene)]
    plume-models/src/lib.rs:#![feature(box_patterns)]
    src/main.rs:#![feature(decl_macro, proc_macro_hygiene)]
    
    % cat rust-toolchain
    nightly-2022-07-19
    
    % rm -f rust-toolchain
    % cargo check
    

    No errors from plume crates, but we get errors in a couple of locked dependencies:

    error[E0422]: cannot find struct, variant or union type `LineColumn` in crate `proc_macro`
       --> /home/user64/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.49/src/wrapper.rs:479:33
        |
    479 |                 let proc_macro::LineColumn { line, column } = s.start();
        |                                 ^^^^^^^^^^ not found in `proc_macro`
        |
    help: consider importing one of these items
        |
    1   + use crate::LineColumn;
        |
    1   + use crate::fallback::LineColumn;
        |
    help: if you import `LineColumn`, refer to it directly
        |
    479 -                 let proc_macro::LineColumn { line, column } = s.start();
    479 +                 let LineColumn { line, column } = s.start();
        |
    
       Compiling generic-array v0.14.6
    error[E0422]: cannot find struct, variant or union type `LineColumn` in crate `proc_macro`
       --> /home/user64/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.49/src/wrapper.rs:496:33
        |
    496 |                 let proc_macro::LineColumn { line, column } = s.end();
        |                                 ^^^^^^^^^^ not found in `proc_macro`
        |
    help: consider importing one of these items
        |
    1   + use crate::LineColumn;
        |
    1   + use crate::fallback::LineColumn;
        |
    help: if you import `LineColumn`, refer to it directly
        |
    496 -                 let proc_macro::LineColumn { line, column } = s.end();
    496 +                 let LineColumn { line, column } = s.end();
        |
    
        Checking once_cell v1.17.0
    error[E0635]: unknown feature `proc_macro_span_shrink`
      --> /home/user64/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.49/src/lib.rs:92:30
       |
    92 |     feature(proc_macro_span, proc_macro_span_shrink)
       |                              ^^^^^^^^^^^^^^^^^^^^^^
    
    

    Let’s see if a full (semver-compatible) deps update works:

    % cargo update
    % cargo check
    

    This succeeds.

    I will let you pick it from here.
    Should be a good learning experience.




  • A good time to refresh my Rust folder as a whole to see what features got stabilized, removed, or subsumed.

    My current list of used unstable features is down to 20.
    Some lang, some lib.
    A couple incomplete.
    Some are more important than others.

    #![feature(adt_const_params)]
    #![feature(async_closure)]
    #![feature(const_type_name)]
    #![feature(duration_constants)]
    #![feature(extract_if)]
    #![feature(generic_arg_infer)]
    #![feature(impl_trait_in_assoc_type)]
    #![feature(iter_array_chunks)]
    #![feature(let_chains)]
    #![feature(macro_metavar_expr)]
    #![feature(map_try_insert)]
    #![feature(never_type)]
    #![feature(once_cell_try)]
    #![feature(proc_macro_hygiene)]
    #![feature(specialization)]
    #![feature(step_trait)]
    #![feature(stmt_expr_attributes)]
    #![feature(try_blocks)]
    #![feature(try_find)]
    #![feature(type_changing_struct_update)]
    

    DISCLAIMER: this is not an endorsement of try_blocks 😐