* Calculates new isRouter value based on provided parameters and * returns it. */
| 1838 | * returns it. |
| 1839 | */ |
| 1840 | static int |
| 1841 | nd6_is_router(int type, int code, int is_new, int old_addr, int new_addr, |
| 1842 | int ln_router) |
| 1843 | { |
| 1844 | |
| 1845 | /* |
| 1846 | * ICMP6 type dependent behavior. |
| 1847 | * |
| 1848 | * NS: clear IsRouter if new entry |
| 1849 | * RS: clear IsRouter |
| 1850 | * RA: set IsRouter if there's lladdr |
| 1851 | * redir: clear IsRouter if new entry |
| 1852 | * |
| 1853 | * RA case, (1): |
| 1854 | * The spec says that we must set IsRouter in the following cases: |
| 1855 | * - If lladdr exist, set IsRouter. This means (1-5). |
| 1856 | * - If it is old entry (!newentry), set IsRouter. This means (7). |
| 1857 | * So, based on the spec, in (1-5) and (7) cases we must set IsRouter. |
| 1858 | * A quetion arises for (1) case. (1) case has no lladdr in the |
| 1859 | * neighbor cache, this is similar to (6). |
| 1860 | * This case is rare but we figured that we MUST NOT set IsRouter. |
| 1861 | * |
| 1862 | * is_new old_addr new_addr NS RS RA redir |
| 1863 | * D R |
| 1864 | * 0 n n (1) c ? s |
| 1865 | * 0 y n (2) c s s |
| 1866 | * 0 n y (3) c s s |
| 1867 | * 0 y y (4) c s s |
| 1868 | * 0 y y (5) c s s |
| 1869 | * 1 -- n (6) c c c s |
| 1870 | * 1 -- y (7) c c s c s |
| 1871 | * |
| 1872 | * (c=clear s=set) |
| 1873 | */ |
| 1874 | switch (type & 0xff) { |
| 1875 | case ND_NEIGHBOR_SOLICIT: |
| 1876 | /* |
| 1877 | * New entry must have is_router flag cleared. |
| 1878 | */ |
| 1879 | if (is_new) /* (6-7) */ |
| 1880 | ln_router = 0; |
| 1881 | break; |
| 1882 | case ND_REDIRECT: |
| 1883 | /* |
| 1884 | * If the icmp is a redirect to a better router, always set the |
| 1885 | * is_router flag. Otherwise, if the entry is newly created, |
| 1886 | * clear the flag. [RFC 2461, sec 8.3] |
| 1887 | */ |
| 1888 | if (code == ND_REDIRECT_ROUTER) |
| 1889 | ln_router = 1; |
| 1890 | else { |
| 1891 | if (is_new) /* (6-7) */ |
| 1892 | ln_router = 0; |
| 1893 | } |
| 1894 | break; |
| 1895 | case ND_ROUTER_SOLICIT: |
| 1896 | /* |
| 1897 | * is_router flag must always be cleared. |