Changes in uspace/srv/net/inetsrv/inetcfg.c [1bbc6dc:fafb8e5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inetcfg.c
r1bbc6dc rfafb8e5 1 1 /* 2 * Copyright (c) 20 24Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 92 92 } 93 93 94 rc = inet_cfg_sync(cfg);95 if (rc != EOK) {96 log_msg(LOG_DEFAULT, LVL_ERROR, "Error saving configuration.");97 return rc;98 }99 100 94 return EOK; 101 95 } … … 104 98 { 105 99 inet_addrobj_t *addr; 106 inet_link_cfg_info_t info;107 unsigned acnt;108 inet_link_t *ilink;109 errno_t rc;110 111 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete()");112 100 113 101 addr = inet_addrobj_get_by_id(addr_id); … … 115 103 return ENOENT; 116 104 117 info.svc_id = addr->ilink->svc_id;118 info.svc_name = str_dup(addr->ilink->svc_name);119 if (info.svc_name == NULL)120 return ENOMEM;121 122 105 inet_addrobj_remove(addr); 123 106 inet_addrobj_delete(addr); 124 107 125 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete(): sync");126 127 rc = inet_cfg_sync(cfg);128 if (rc != EOK) {129 log_msg(LOG_DEFAULT, LVL_ERROR, "Error saving configuration.");130 free(info.svc_name);131 return rc;132 }133 134 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete(): get link by ID");135 136 ilink = inet_link_get_by_id(info.svc_id);137 if (ilink == NULL) {138 log_msg(LOG_DEFAULT, LVL_ERROR, "Error finding link.");139 return ENOENT;140 }141 142 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete(): check addrobj count");143 144 /* If there are no configured addresses left, autoconfigure link */145 acnt = inet_addrobj_cnt_by_link(ilink);146 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete(): acnt=%u", acnt);147 if (acnt == 0)148 inet_link_autoconf_link(&info);149 150 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete(): DONE");151 108 return EOK; 152 109 } … … 220 177 linfo->def_mtu = ilink->def_mtu; 221 178 if (ilink->mac_valid) { 222 linfo->mac_addr = ilink->mac;179 addr48(ilink->mac, linfo->mac_addr); 223 180 } else { 224 memset( &linfo->mac_addr, 0, sizeof(linfo->mac_addr));181 memset(linfo->mac_addr, 0, sizeof(linfo->mac_addr)); 225 182 } 226 183 … … 236 193 inet_addr_t *router, sysarg_t *sroute_id) 237 194 { 238 errno_t rc;239 195 inet_sroute_t *sroute; 240 196 … … 251 207 252 208 *sroute_id = sroute->id; 253 254 rc = inet_cfg_sync(cfg);255 if (rc != EOK) {256 log_msg(LOG_DEFAULT, LVL_ERROR, "Error saving configuration.");257 return rc;258 }259 260 209 return EOK; 261 210 } … … 263 212 static errno_t inetcfg_sroute_delete(sysarg_t sroute_id) 264 213 { 265 errno_t rc;266 214 inet_sroute_t *sroute; 267 215 … … 272 220 inet_sroute_remove(sroute); 273 221 inet_sroute_delete(sroute); 274 275 rc = inet_cfg_sync(cfg);276 if (rc != EOK) {277 log_msg(LOG_DEFAULT, LVL_ERROR, "Error saving configuration.");278 return rc;279 }280 222 281 223 return EOK; … … 863 805 } 864 806 865 static errno_t inet_cfg_load(const char *cfg_path)866 {867 sif_doc_t *doc = NULL;868 sif_node_t *rnode;869 sif_node_t *naddrs;870 sif_node_t *nroutes;871 const char *ntype;872 errno_t rc;873 874 rc = sif_load(cfg_path, &doc);875 if (rc != EOK)876 goto error;877 878 rnode = sif_get_root(doc);879 naddrs = sif_node_first_child(rnode);880 ntype = sif_node_get_type(naddrs);881 if (str_cmp(ntype, "addresses") != 0) {882 rc = EIO;883 goto error;884 }885 886 rc = inet_addrobjs_load(naddrs);887 if (rc != EOK)888 goto error;889 890 nroutes = sif_node_next_child(naddrs);891 ntype = sif_node_get_type(nroutes);892 if (str_cmp(ntype, "static-routes") != 0) {893 rc = EIO;894 goto error;895 }896 897 rc = inet_sroutes_load(nroutes);898 if (rc != EOK)899 goto error;900 901 sif_delete(doc);902 return EOK;903 error:904 if (doc != NULL)905 sif_delete(doc);906 return rc;907 908 }909 910 static errno_t inet_cfg_save(const char *cfg_path)911 {912 sif_doc_t *doc = NULL;913 sif_node_t *rnode;914 sif_node_t *nsroutes;915 sif_node_t *naddrobjs;916 errno_t rc;917 918 log_msg(LOG_DEFAULT, LVL_NOTE, "inet_cfg_save(%s)", cfg_path);919 920 rc = sif_new(&doc);921 if (rc != EOK)922 goto error;923 924 rnode = sif_get_root(doc);925 926 /* Address objects */927 928 rc = sif_node_append_child(rnode, "addresses", &naddrobjs);929 if (rc != EOK)930 goto error;931 932 rc = inet_addrobjs_save(naddrobjs);933 if (rc != EOK)934 goto error;935 936 /* Static routes */937 938 rc = sif_node_append_child(rnode, "static-routes", &nsroutes);939 if (rc != EOK)940 goto error;941 942 rc = inet_sroutes_save(nsroutes);943 if (rc != EOK)944 goto error;945 946 /* Save */947 948 rc = sif_save(doc, cfg_path);949 if (rc != EOK)950 goto error;951 952 sif_delete(doc);953 return EOK;954 error:955 if (doc != NULL)956 sif_delete(doc);957 return rc;958 }959 960 /** Open internet server configuration.961 *962 * @param cfg_path Configuration file path963 * @param rcfg Place to store pointer to configuration object964 * @return EOK on success or an error code965 */966 errno_t inet_cfg_open(const char *cfg_path, inet_cfg_t **rcfg)967 {968 inet_cfg_t *cfg;969 errno_t rc;970 971 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_cfg_open(%s)", cfg_path);972 973 rc = inet_cfg_load(cfg_path);974 if (rc != EOK) {975 log_msg(LOG_DEFAULT, LVL_WARN, "inet_cfg_open(%s) :"976 "could not load configuration.", cfg_path);977 }978 979 cfg = calloc(1, sizeof(inet_cfg_t));980 if (cfg == NULL)981 return ENOMEM;982 983 cfg->cfg_path = str_dup(cfg_path);984 if (cfg->cfg_path == NULL) {985 free(cfg);986 return ENOMEM;987 }988 989 *rcfg = cfg;990 return EOK;991 }992 993 errno_t inet_cfg_sync(inet_cfg_t *cfg)994 {995 log_msg(LOG_DEFAULT, LVL_NOTE, "inet_cfg_sync(cfg=%p)", cfg);996 return inet_cfg_save(cfg->cfg_path);997 }998 999 void inet_cfg_close(inet_cfg_t *cfg)1000 {1001 free(cfg);1002 }1003 1004 807 /** @} 1005 808 */
Note:
See TracChangeset
for help on using the changeset viewer.