On 8/28/10 10:05 AM, Tom Eastep wrote:

> 
> I have yet to decide what I want to do about it.
> 
> Shorewall currently uses this function to create shell variable names
> from interface names:
> ------------------
> #
> # Transform the passed interface name into a legal shell variable name.
> #
> sub chain_base($) {
>     my $chain = $_[0];
> 
>     $chain =~ s/^@/at_/;
>     $chain =~ tr/[....@]/_/;
>     $chain =~ s/\+$//;
>     $chain;
> }
> --------------------
> 
> This approach is already flawed since it can easily result in name
> collisions.
> 
> I could always manufacture names but that makes the generated code hard
> to read.
> 
> I could use the name as is (e.g., 'eth0' becomes SW_ETH0_IS_USABLE)
> unless the name is not a valid shell identifier in which case I would
> manufacture a name (e.g. 'eth0.4' because SW__n_IS_USABLE, where 'n' is
> a serially-assigned integer).
> 
> Both of these approaches risk breaking existing configurations that use
> one of these variable names in their 'start' or 'started' scripts
> (although I broke those configs back in 4.4.8 as well when I added the
> SW_ prefix). The second approach breaks fewer configs than the first does.
> 

I've decided to follow the second approach as follows:

- Replace periods with underscores
- Strip trailing '+'

If the resulting name is valid for a shell-variable then use it.

Otherwise:

- Strip out all characters that are not valid in a shell variable name.
- If the result begins with a digit, preface the name with 'if_'.
- Add a suffix consisting of '_' followed by a unique sequence number.

The above algorithm results in no change for VLAN and wildcard names. It
will be in Beta 3.

-Tom
-- 
Tom Eastep        \ When I die, I want to go like my Grandfather who
Shoreline,         \ died peacefully in his sleep. Not screaming like
Washington, USA     \ all of the passengers in his car
http://shorewall.net \________________________________________________

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Shorewall-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/shorewall-devel

Reply via email to